c871c5cf319fc8c7662b26aa825a7e54cc847001
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl.Operations / XslCopy.cs
1 //
2 // XslCopy.cs
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //      Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 //      
8 // (C) 2003 Ben Maurer
9 // (C) 2003 Atsushi Enomoto
10 //
11
12 using System;
13 using System.Collections;
14 using System.Xml;
15 using System.Xml.XPath;
16 using System.Xml.Xsl;
17
18 namespace Mono.Xml.Xsl.Operations {
19         public class XslCopy : XslCompiledElement {
20                 XslOperation children;
21                 XmlQualifiedName [] useAttributeSets;
22                 
23                 public XslCopy (Compiler c) : base (c) {}
24                 
25                 protected override void Compile (Compiler c)
26                 {
27                         useAttributeSets = c.ParseQNameListAttribute ("use-attribute-sets");
28                         
29                         if (!c.Input.MoveToFirstChild ()) return;
30                         children = c.CompileTemplateContent();
31                         c.Input.MoveToParent ();
32                 }
33
34                 public override void Evaluate (XslTransformProcessor p)
35                 {
36                         switch (p.CurrentNode.NodeType)
37                         {
38                         case XPathNodeType.Root:
39                                 if (children != null) children.Evaluate (p);
40                                 break;
41                         case XPathNodeType.Element:
42                                 p.Out.WriteStartElement (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI);
43                                 
44                                 if (useAttributeSets != null)
45                                         foreach (XmlQualifiedName s in useAttributeSets)
46                                                 p.ResolveAttributeSet (s).Evaluate (p);
47                         
48                                 if (children != null) children.Evaluate (p);
49                                 p.Out.WriteEndElement ();
50                                 break;
51                         case XPathNodeType.Attribute:
52                                 p.Out.WriteAttributeString (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI, p.CurrentNode.Value);
53                                 break;
54                         
55                         case XPathNodeType.SignificantWhitespace:
56                         case XPathNodeType.Text:
57                         case XPathNodeType.Whitespace:
58                                 p.Out.WriteString (p.CurrentNode.Value);
59                                 break;
60                         
61                         case XPathNodeType.Comment:
62                                 p.Out.WriteComment (p.CurrentNode.Value);
63                                 break;
64                         
65                         case XPathNodeType.ProcessingInstruction:
66                                 p.Out.WriteProcessingInstruction (p.CurrentNode.Name, p.CurrentNode.Value);
67                                 break;
68                         
69                         default:
70                                 Console.WriteLine ("unhandled node type {0}", p.CurrentNode.NodeType);
71                                 break;
72                         }
73                 }
74         }
75 }