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 p.Out.WriteStartElement (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI);
48 p.TryStylesheetNamespaceOutput ();
49 if (useAttributeSets != null)
50 foreach (XmlQualifiedName s in useAttributeSets)
51 p.ResolveAttributeSet (s).Evaluate (p);
53 if (p.CurrentNode.MoveToFirstNamespace (XPathNamespaceScope.Local)) {
55 p.Out.WriteNamespaceDecl (p.CurrentNode.LocalName, p.CurrentNode.Value);
56 } while (p.CurrentNode.MoveToNextNamespace (XPathNamespaceScope.Local));
57 p.CurrentNode.MoveToParent ();
60 if (children != null) children.Evaluate (p);
61 p.Out.WriteFullEndElement ();
63 case XPathNodeType.Attribute:
64 p.Out.WriteAttributeString (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI, p.CurrentNode.Value);
67 case XPathNodeType.SignificantWhitespace:
68 case XPathNodeType.Text:
69 case XPathNodeType.Whitespace:
70 p.Out.WriteString (p.CurrentNode.Value);
73 case XPathNodeType.Comment:
74 p.Out.WriteComment (p.CurrentNode.Value);
77 case XPathNodeType.ProcessingInstruction:
78 p.Out.WriteProcessingInstruction (p.CurrentNode.Name, p.CurrentNode.Value);
82 Console.WriteLine ("unhandled node type {0}", p.CurrentNode.NodeType);