Exemplo n.º 1
0
        public override void Evaluate(XslTransformProcessor p)
        {
            if (p.Debugger != null)
            {
                p.Debugger.DebugExecute(p, this.DebugInput);
            }

            XPathNavigator nav = p.CurrentNode;

            switch (nav.NodeType)
            {
            case XPathNodeType.Root:
                if (p.Out.CanProcessAttributes && useAttributeSets != null)
                {
                    foreach (XmlQualifiedName s in useAttributeSets)
                    {
                        XslAttributeSet attset = p.ResolveAttributeSet(s);
                        if (attset == null)
                        {
                            throw new XsltException("Attribute set was not found", null, nav);
                        }
                        attset.Evaluate(p);
                    }
                }

                if (children != null)
                {
                    children.Evaluate(p);
                }
                break;

            case XPathNodeType.Element:
                bool   isCData = p.InsideCDataElement;
                string prefix  = nav.Prefix;
                p.PushElementState(prefix, nav.LocalName, nav.NamespaceURI, true);
                p.Out.WriteStartElement(prefix, nav.LocalName, nav.NamespaceURI);

                if (useAttributeSets != null)
                {
                    foreach (XmlQualifiedName s in useAttributeSets)
                    {
                        p.ResolveAttributeSet(s).Evaluate(p);
                    }
                }

                if (nav.MoveToFirstNamespace(XPathNamespaceScope.ExcludeXml))
                {
                    do
                    {
                        if (nav.LocalName == prefix)
                        {
                            continue;
                        }
                        p.Out.WriteNamespaceDecl(nav.LocalName, nav.Value);
                    } while (nav.MoveToNextNamespace(XPathNamespaceScope.ExcludeXml));
                    nav.MoveToParent();
                }

                if (children != null)
                {
                    children.Evaluate(p);
                }

                p.Out.WriteFullEndElement();
                p.PopCDataState(isCData);
                break;

            case XPathNodeType.Attribute:
                p.Out.WriteAttributeString(nav.Prefix, nav.LocalName, nav.NamespaceURI, nav.Value);
                break;

            case XPathNodeType.SignificantWhitespace:
            case XPathNodeType.Whitespace:
                bool cdata = p.Out.InsideCDataSection;
                p.Out.InsideCDataSection = false;
                p.Out.WriteString(nav.Value);
                p.Out.InsideCDataSection = cdata;
                break;

            case XPathNodeType.Text:
                p.Out.WriteString(nav.Value);
                break;

            case XPathNodeType.Comment:
                p.Out.WriteComment(nav.Value);
                break;

            case XPathNodeType.ProcessingInstruction:
                p.Out.WriteProcessingInstruction(nav.Name, nav.Value);
                break;

            case XPathNodeType.Namespace:
                if (p.XPathContext.ElementPrefix != nav.Name)
                {
                    p.Out.WriteNamespaceDecl(nav.Name, nav.Value);
                }
                break;

            default:
//				Console.WriteLine ("unhandled node type {0}", nav.NodeType);
                break;
            }
        }
Exemplo n.º 2
0
        public override void Evaluate(XslTransformProcessor p)
        {
            if (p.Debugger != null)
            {
                p.Debugger.DebugExecute(p, base.DebugInput);
            }
            XPathNavigator currentNode = p.CurrentNode;

            switch (currentNode.NodeType)
            {
            case XPathNodeType.Root:
                if (p.Out.CanProcessAttributes && this.useAttributeSets != null)
                {
                    foreach (XmlQualifiedName name in this.useAttributeSets)
                    {
                        XslAttributeSet xslAttributeSet = p.ResolveAttributeSet(name);
                        if (xslAttributeSet == null)
                        {
                            throw new XsltException("Attribute set was not found", null, currentNode);
                        }
                        xslAttributeSet.Evaluate(p);
                    }
                }
                if (this.children != null)
                {
                    this.children.Evaluate(p);
                }
                break;

            case XPathNodeType.Element:
            {
                bool   insideCDataElement = p.InsideCDataElement;
                string prefix             = currentNode.Prefix;
                p.PushElementState(prefix, currentNode.LocalName, currentNode.NamespaceURI, true);
                p.Out.WriteStartElement(prefix, currentNode.LocalName, currentNode.NamespaceURI);
                if (this.useAttributeSets != null)
                {
                    foreach (XmlQualifiedName name2 in this.useAttributeSets)
                    {
                        p.ResolveAttributeSet(name2).Evaluate(p);
                    }
                }
                if (currentNode.MoveToFirstNamespace(XPathNamespaceScope.ExcludeXml))
                {
                    do
                    {
                        if (!(currentNode.LocalName == prefix))
                        {
                            p.Out.WriteNamespaceDecl(currentNode.LocalName, currentNode.Value);
                        }
                    }while (currentNode.MoveToNextNamespace(XPathNamespaceScope.ExcludeXml));
                    currentNode.MoveToParent();
                }
                if (this.children != null)
                {
                    this.children.Evaluate(p);
                }
                p.Out.WriteFullEndElement();
                p.PopCDataState(insideCDataElement);
                break;
            }

            case XPathNodeType.Attribute:
                p.Out.WriteAttributeString(currentNode.Prefix, currentNode.LocalName, currentNode.NamespaceURI, currentNode.Value);
                break;

            case XPathNodeType.Namespace:
                if (p.XPathContext.ElementPrefix != currentNode.Name)
                {
                    p.Out.WriteNamespaceDecl(currentNode.Name, currentNode.Value);
                }
                break;

            case XPathNodeType.Text:
                p.Out.WriteString(currentNode.Value);
                break;

            case XPathNodeType.SignificantWhitespace:
            case XPathNodeType.Whitespace:
            {
                bool insideCDataSection = p.Out.InsideCDataSection;
                p.Out.InsideCDataSection = false;
                p.Out.WriteString(currentNode.Value);
                p.Out.InsideCDataSection = insideCDataSection;
                break;
            }

            case XPathNodeType.ProcessingInstruction:
                p.Out.WriteProcessingInstruction(currentNode.Name, currentNode.Value);
                break;

            case XPathNodeType.Comment:
                p.Out.WriteComment(currentNode.Value);
                break;
            }
        }