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 (children != null) children.Evaluate (p);
41 case XPathNodeType.Element:
42 p.Out.WriteStartElement (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI);
44 if (useAttributeSets != null)
45 foreach (XmlQualifiedName s in useAttributeSets)
46 p.ResolveAttributeSet (s).Evaluate (p);
48 if (children != null) children.Evaluate (p);
49 p.Out.WriteEndElement ();
51 case XPathNodeType.Attribute:
52 p.Out.WriteAttributeString (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI, p.CurrentNode.Value);
55 case XPathNodeType.SignificantWhitespace:
56 case XPathNodeType.Text:
57 case XPathNodeType.Whitespace:
58 p.Out.WriteString (p.CurrentNode.Value);
61 case XPathNodeType.Comment:
62 p.Out.WriteComment (p.CurrentNode.Value);
65 case XPathNodeType.ProcessingInstruction:
66 p.Out.WriteProcessingInstruction (p.CurrentNode.Name, p.CurrentNode.Value);
70 Console.WriteLine ("unhandled node type {0}", p.CurrentNode.NodeType);