5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
9 // (C) 2003 Atsushi Enomoto
13 using System.Collections;
15 using System.Xml.XPath;
18 namespace Mono.Xml.Xsl.Operations {
19 public class XslCopy : XslCompiledElement {
20 XslOperation children;
21 XmlQualifiedName [] useAttributeSets;
23 public XslCopy (Compiler c) : base (c) {}
25 protected override void Compile (Compiler c)
27 if (c.Input.MoveToFirstAttribute ()) {
29 if (c.Input.NamespaceURI == String.Empty && c.Input.LocalName != "use-attribute-sets")
30 throw new XsltCompileException ("Unrecognized attribute \"" + c.Input.Name + "\" in XSLT copy element.", null, c.Input);
31 } while (c.Input.MoveToNextAttribute ());
32 c.Input.MoveToParent ();
35 useAttributeSets = c.ParseQNameListAttribute ("use-attribute-sets");
37 if (!c.Input.MoveToFirstChild ()) return;
38 children = c.CompileTemplateContent();
39 c.Input.MoveToParent ();
42 public override void Evaluate (XslTransformProcessor p)
44 switch (p.CurrentNode.NodeType)
46 case XPathNodeType.Root:
47 if (p.Out.CanProcessAttributes && useAttributeSets != null)
48 foreach (XmlQualifiedName s in useAttributeSets) {
49 XslAttributeSet attset = p.ResolveAttributeSet (s);
51 throw new XsltException ("Attribute set was not found.", null, p.CurrentNode);
55 if (children != null) children.Evaluate (p);
57 case XPathNodeType.Element:
58 bool isCData = p.InsideCDataElement;
59 p.PushElementState (p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI, true);
60 p.Out.WriteStartElement (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI);
62 p.TryStylesheetNamespaceOutput (null);
63 if (useAttributeSets != null)
64 foreach (XmlQualifiedName s in useAttributeSets)
65 p.ResolveAttributeSet (s).Evaluate (p);
67 if (p.CurrentNode.MoveToFirstNamespace (XPathNamespaceScope.Local)) {
69 p.Out.WriteNamespaceDecl (p.CurrentNode.LocalName, p.CurrentNode.Value);
70 } while (p.CurrentNode.MoveToNextNamespace (XPathNamespaceScope.Local));
71 p.CurrentNode.MoveToParent ();
74 if (children != null) children.Evaluate (p);
76 p.Out.WriteFullEndElement ();
77 p.PopCDataState (isCData);
79 case XPathNodeType.Attribute:
80 p.Out.WriteAttributeString (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI, p.CurrentNode.Value);
83 case XPathNodeType.SignificantWhitespace:
84 case XPathNodeType.Whitespace:
85 bool cdata = p.Out.InsideCDataSection;
86 p.Out.InsideCDataSection = false;
87 p.Out.WriteString (p.CurrentNode.Value);
88 p.Out.InsideCDataSection = cdata;
90 case XPathNodeType.Text:
91 p.Out.WriteString (p.CurrentNode.Value);
94 case XPathNodeType.Comment:
95 p.Out.WriteComment (p.CurrentNode.Value);
98 case XPathNodeType.ProcessingInstruction:
99 p.Out.WriteProcessingInstruction (p.CurrentNode.Name, p.CurrentNode.Value);
102 case XPathNodeType.Namespace:
103 p.Out.WriteNamespaceDecl (p.CurrentNode.Name, p.CurrentNode.Value);
107 // Console.WriteLine ("unhandled node type {0}", p.CurrentNode.NodeType);