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 useAttributeSets = c.ParseQNameListAttribute ("use-attribute-sets");
29 if (!c.Input.MoveToFirstChild ()) return;
30 children = c.CompileTemplateContent();
31 c.Input.MoveToParent ();
34 public override void Evaluate (XslTransformProcessor p)
36 switch (p.CurrentNode.NodeType)
38 case XPathNodeType.Root:
39 if (p.Out.CanProcessAttributes && useAttributeSets != null)
40 foreach (XmlQualifiedName s in useAttributeSets)
41 p.ResolveAttributeSet (s).Evaluate (p);
43 if (children != null) children.Evaluate (p);
45 case XPathNodeType.Element:
46 bool cdataStarted = false;
47 if (!p.InsideCDataElement && p.PushCDataState (p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI))
49 p.Out.WriteStartElement (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI);
51 p.TryStylesheetNamespaceOutput (null);
52 if (useAttributeSets != null)
53 foreach (XmlQualifiedName s in useAttributeSets)
54 p.ResolveAttributeSet (s).Evaluate (p);
56 if (p.CurrentNode.MoveToFirstNamespace (XPathNamespaceScope.Local)) {
58 p.Out.WriteNamespaceDecl (p.CurrentNode.LocalName, p.CurrentNode.Value);
59 } while (p.CurrentNode.MoveToNextNamespace (XPathNamespaceScope.Local));
60 p.CurrentNode.MoveToParent ();
63 if (children != null) children.Evaluate (p);
65 p.Out.WriteFullEndElement ();
69 case XPathNodeType.Attribute:
70 p.Out.WriteAttributeString (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI, p.CurrentNode.Value);
73 case XPathNodeType.SignificantWhitespace:
74 case XPathNodeType.Text:
75 case XPathNodeType.Whitespace:
76 p.Out.WriteString (p.CurrentNode.Value);
79 case XPathNodeType.Comment:
80 p.Out.WriteComment (p.CurrentNode.Value);
83 case XPathNodeType.ProcessingInstruction:
84 p.Out.WriteProcessingInstruction (p.CurrentNode.Name, p.CurrentNode.Value);
88 Console.WriteLine ("unhandled node type {0}", p.CurrentNode.NodeType);