Esempio n. 1
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State)
            {
            case Initialized:
                Debug.Assert(frame.NodeSet != null);
                Debug.Assert(this.selectKey != Compiler.InvalidQueryKey);
                XPathExpression expr   = processor.GetValueQuery(this.selectKey);
                object          result = frame.Node.Evaluate(expr);

                XPathNodeIterator nodeSet = result as XPathNodeIterator;
                if (nodeSet != null)
                {
                    processor.PushActionFrame(CopyNodeSetAction.GetAction(), nodeSet);
                    frame.State = NodeSetCopied;
                    break;
                }

                XPathNavigator nav = result as XPathNavigator;
                if (nav != null)
                {
                    processor.PushActionFrame(CopyNodeSetAction.GetAction(), new XPathSingletonIterator(nav));
                    frame.State = NodeSetCopied;
                    break;
                }

                string value = XmlConvert.ToXPathString(result);
                if (processor.TextEvent(value))
                {
                    frame.Finished();
                }
                else
                {
                    frame.StoredOutput = value;
                    frame.State        = ResultStored;
                }
                break;

            case ResultStored:
                Debug.Assert(frame.StoredOutput != null);
                processor.TextEvent(frame.StoredOutput);
                frame.Finished();
                break;

            case NodeSetCopied:
                Debug.Assert(frame.State == NodeSetCopied);
                frame.Finished();
                break;
            }
        }
Esempio n. 2
0
 public override bool Output(Processor processor, ActionFrame frame) {
     bool res;
     res = processor.BeginEvent(XPathNodeType.Namespace, /*prefix:*/null, this.name, this.namespaceUri, /*empty:*/false);
     Debug.Assert(res); // Namespace node as any other attribute can't fail because it doesn't signal record change
     res = processor.TextEvent(this.namespaceUri);
     Debug.Assert(res);
     res = processor.EndEvent(XPathNodeType.Namespace);
     Debug.Assert(res);
     return true;
 }
        public override bool Output(Processor processor, ActionFrame frame)
        {
            bool res;

            res = processor.BeginEvent(XPathNodeType.Namespace, /*prefix:*/ null, this.name, this.namespaceUri, /*empty:*/ false);
            Debug.Assert(res); // Namespace node as any other attribute can't fail because it doesn't signal record change
            res = processor.TextEvent(this.namespaceUri);
            Debug.Assert(res);
            res = processor.EndEvent(XPathNodeType.Namespace);
            Debug.Assert(res);
            return(true);
        }
Esempio n. 4
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State)
            {
            case Initialized:
                Debug.Assert(frame != null);
                Debug.Assert(frame.NodeSet != null);

                if (this.selectKey == Compiler.InvalidQueryKey)
                {
                    throw new XsltException(Res.Xslt_InvalidXPath, new string[] { select });
                }

                string value = processor.ValueOf(frame, this.selectKey);

                if (processor.TextEvent(value, disableOutputEscaping))
                {
                    frame.Finished();
                }
                else
                {
                    frame.StoredOutput = value;
                    frame.State        = ResultStored;
                }
                break;

            case ResultStored:
                Debug.Assert(frame.StoredOutput != null);
                processor.TextEvent(frame.StoredOutput);
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid ValueOfAction execution state");
                break;
            }
        }
Esempio n. 5
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                if (processor.TextEvent(this.text, disableOutputEscaping)) {
                    frame.Finished();
                }
                break;

            default:
                Debug.Fail("Invalid execution state in TextAction");
                break;
            }
        }
Esempio n. 6
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                Debug.Assert(frame.NodeSet != null);
                Debug.Assert(this.selectKey != Compiler.InvalidQueryKey);
                XPathExpression expr = processor.GetValueQuery(this.selectKey);
                object result = frame.Node.Evaluate(expr);

                XPathNodeIterator nodeSet = result as XPathNodeIterator;
                if (nodeSet != null) {
                    processor.PushActionFrame(CopyNodeSetAction.GetAction(), nodeSet);
                    frame.State = NodeSetCopied;
                    break;
                }

                XPathNavigator nav = result as XPathNavigator;
                if (nav != null) {
                    processor.PushActionFrame(CopyNodeSetAction.GetAction(), new XPathSingletonIterator(nav));
                    frame.State = NodeSetCopied;
                    break; 
                }

                string value = XmlConvert.ToXPathString(result);
                if (processor.TextEvent(value)) {
                    frame.Finished();
                }
                else {
                    frame.StoredOutput = value;
                    frame.State        = ResultStored;
                }
                break;

            case ResultStored:
                Debug.Assert(frame.StoredOutput != null);
                processor.TextEvent(frame.StoredOutput);
                frame.Finished();
                break;

            case NodeSetCopied:
                Debug.Assert(frame.State == NodeSetCopied);
                frame.Finished();
                break;
            }
        }
Esempio n. 7
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State)
            {
            case Initialized:
                if (processor.TextEvent(this.text, disableOutputEscaping))
                {
                    frame.Finished();
                }
                break;

            default:
                Debug.Fail("Invalid execution state in TextAction");
                break;
            }
        }
Esempio n. 8
0
        internal override void Execute(Processor processor, ActionFrame frame)
        {
            Debug.Assert(processor != null && frame != null);
            ArrayList list = processor.NumberList;

            switch (frame.State)
            {
            case Initialized:
                Debug.Assert(frame != null);
                Debug.Assert(frame.NodeSet != null);
                list.Clear();
                if (this.value != null)
                {
                    object valueObject = SimplifyValue(processor.Evaluate(frame, this.valueKey));
                    double valueDouble = 0;
                    try {
                        valueDouble = XmlConvert.ToXPathDouble(valueObject);
                    }
                    catch (FormatException) {}
                    if (0.5 <= valueDouble && valueDouble < double.PositiveInfinity)
                    {
                        Debug.Assert(!double.IsNaN(valueDouble), "I belive it should be filtered by if condition");
                        list.Add(Math.Floor(valueDouble + 0.5));   // See XPath round for detailes on the trick with Floor()
                    }
                    else
                    {
                        // It is an error if the number is NaN, infinite or less than 0.5; an XSLT processor may signal the error;
                        // if it does not signal the error, it must recover by converting the number to a string as if by a call
                        // to the string function and inserting the resulting string into the result tree.
                        frame.StoredOutput = XmlConvert.ToXPathString(valueObject);
                        goto case OutputNumber;
                    }
                }
                else if (this.level == "any")
                {
                    int number = numberAny(processor, frame);
                    if (number != 0)
                    {
                        list.Add((double)number);
                    }
                }
                else
                {
                    bool           multiple    = (this.level == "multiple");
                    XPathNavigator contextNode = frame.Node;         // context of xsl:number element. We using this node in MatchCountKey()
                    XPathNavigator countNode   = frame.Node.Clone(); // node we count for
                    if (countNode.NodeType == XPathNodeType.Attribute)
                    {
                        countNode.MoveToParent();
                    }
                    while (moveToCount(countNode, processor, contextNode))
                    {
                        list.Insert(0, (double)numberCount(countNode, processor, contextNode));
                        if (!multiple || !countNode.MoveToParent())
                        {
                            break;
                        }
                    }
                    if (!checkFrom(processor, countNode))
                    {
                        list.Clear();
                    }
                }

                /*CalculatingFormat:*/
                frame.StoredOutput = Format(list,
                                            this.formatAvt == null ? this.formatList   : ParseFormat(this.formatAvt.Evaluate(processor, frame)),
                                            this.langAvt == null ? this.lang         : this.langAvt.Evaluate(processor, frame),
                                            this.letterAvt == null ? this.letter       : ParseLetter(this.letterAvt.Evaluate(processor, frame)),
                                            this.groupingSepAvt == null ? this.groupingSep  : this.groupingSepAvt.Evaluate(processor, frame),
                                            this.groupingSizeAvt == null ? this.groupingSize : this.groupingSizeAvt.Evaluate(processor, frame)
                                            );
                goto case OutputNumber;

            case OutputNumber:
                Debug.Assert(frame.StoredOutput != null);
                if (!processor.TextEvent(frame.StoredOutput))
                {
                    frame.State = OutputNumber;
                    break;
                }
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid Number Action execution state");
                break;
            }
        }
Esempio n. 9
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);
            ArrayList list = processor.NumberList;
            switch (frame.State) {
            case Initialized:
                Debug.Assert(frame != null);
                Debug.Assert(frame.NodeSet != null);
                list.Clear();
                if (this.value != null) {
                    object valueObject = processor.Evaluate(frame, this.valueKey);
                    double valueDouble = 0;
                    try {
                        valueDouble = Processor.ToDouble(valueObject);
                    }
                    catch (FormatException) {}
                    if (0.5 <= valueDouble && valueDouble < double.PositiveInfinity) {
                        Debug.Assert(! double.IsNaN(valueDouble), "I belive it should be filtered by if condition");
                        list.Add(Math.Floor(valueDouble + 0.5));   // See XPath round for detailes on the trick with Floor()
                    }
                    else {
                        // It is an error if the number is NaN, infinite or less than 0.5; an XSLT processor may signal the error; 
                        // if it does not signal the error, it must recover by converting the number to a string as if by a call 
                        // to the string function and inserting the resulting string into the result tree.
                        frame.StoredOutput = XmlConvert.ToXPathString(valueObject);
                        goto case OutputNumber;
                    }
                }
                else if (this.level == "any") {
                    int number = numberAny(processor, frame);
                    if (number != 0) {
                        list.Add(number);
                    }
                }
                else {
                    bool multiple = (this.level == "multiple");
                    XPathNavigator contextNode = frame.Node;         // context of xsl:number element. We using this node in MatchCountKey()
                    XPathNavigator countNode   = frame.Node.Clone(); // node we count for
                    if(countNode.NodeType == XPathNodeType.Attribute) {
                        countNode.MoveToParent();
                    }
                    while(moveToCount(countNode, processor, contextNode)) {
                        list.Insert(0, numberCount(countNode, processor, contextNode));
                        if(! multiple || ! countNode.MoveToParent()) {
                            break;
                        }
                    }
                    if(! checkFrom(processor, countNode)) {
                        list.Clear();
                    }
                }

                /*CalculatingFormat:*/
                frame.StoredOutput = Format(list, 
                    this.formatAvt       == null ? this.formatList   : ParseFormat(this.formatAvt.Evaluate(processor, frame)), 
                    this.langAvt         == null ? this.lang         : this.langAvt        .Evaluate(processor, frame), 
                    this.letterAvt       == null ? this.letter       : ParseLetter(this.letterAvt.Evaluate(processor, frame)), 
                    this.groupingSepAvt  == null ? this.groupingSep  : this.groupingSepAvt .Evaluate(processor, frame), 
                    this.groupingSizeAvt == null ? this.groupingSize : this.groupingSizeAvt.Evaluate(processor, frame)
                );
                goto case OutputNumber;
            case OutputNumber :
                Debug.Assert(frame.StoredOutput != null);
                if (! processor.TextEvent(frame.StoredOutput)) {
                    frame.State        = OutputNumber;
                    break;
                }
                frame.Finished();
                break;
            default:
                Debug.Fail("Invalid Number Action execution state");
                break;
            }            
        }
Esempio n. 10
0
 public override bool Output(Processor processor, ActionFrame frame)
 {
     Debug.Assert(key != Compiler.InvalidQueryKey);
     return(processor.TextEvent(processor.EvaluateString(frame, this.key)));
 }
Esempio n. 11
0
        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(processor != null && frame != null);

            switch (frame.State) {
            case Initialized:
                Debug.Assert(frame != null);
                Debug.Assert(frame.NodeSet != null);

                if (this.selectKey == Compiler.InvalidQueryKey) {
                    throw new XsltException(Res.Xslt_InvalidXPath,  new string[] { select });
                }

                string value = processor.ValueOf(frame, this.selectKey);

                if (processor.TextEvent(value, disableOutputEscaping)) {
                    frame.Finished();
                }
                else {
                    frame.StoredOutput = value;
                    frame.State        = ResultStored;
                }
                break;

            case ResultStored:
                Debug.Assert(frame.StoredOutput != null);
                processor.TextEvent(frame.StoredOutput);
                frame.Finished();
                break;

            default:
                Debug.Fail("Invalid ValueOfAction execution state");
                break;
            }
        }
Esempio n. 12
0
 public override bool Output(Processor processor, ActionFrame frame) {
     Debug.Assert(key != Compiler.InvalidQueryKey);
     return processor.TextEvent(processor.EvaluateString(frame, this.key));
 }
Esempio n. 13
0
 private static bool SendTextEvent(Processor processor, XPathNavigator node) {
     Debug.Assert(node.NodeType == XPathNodeType.Attribute);
     return processor.TextEvent(node.Value);
 }
Esempio n. 14
0
 private static bool SendTextEvent(Processor processor, XPathNavigator node)
 {
     Debug.Assert(node.NodeType == XPathNodeType.Attribute);
     return(processor.TextEvent(node.Value));
 }
Esempio n. 15
0
 public override bool Output(Processor processor, ActionFrame frame)
 {
     return(processor.TextEvent(this.text));
 }
Esempio n. 16
0
 public override bool Output(Processor processor, ActionFrame frame) {
     return processor.TextEvent(this.text);
 }