2003-12-20 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl.Operations / XslCopy.cs
index 9cf62d8e645181702e950f88e2ea6ee80a92a075..40d3d2d7ebc0a5599f5dd9e7dac1b1a63737c16a 100644 (file)
@@ -24,6 +24,14 @@ namespace Mono.Xml.Xsl.Operations {
                
                protected override void Compile (Compiler c)
                {
+                       if (c.Input.MoveToFirstAttribute ()) {
+                               do {
+                                       if (c.Input.NamespaceURI == String.Empty && c.Input.LocalName != "use-attribute-sets")
+                                               throw new XsltCompileException ("Unrecognized attribute \"" + c.Input.Name + "\" in XSLT copy element.", null, c.Input);
+                               } while (c.Input.MoveToNextAttribute ());
+                               c.Input.MoveToParent ();
+                       }
+
                        useAttributeSets = c.ParseQNameListAttribute ("use-attribute-sets");
                        
                        if (!c.Input.MoveToFirstChild ()) return;
@@ -37,15 +45,21 @@ namespace Mono.Xml.Xsl.Operations {
                        {
                        case XPathNodeType.Root:
                                if (p.Out.CanProcessAttributes && useAttributeSets != null)
-                                       foreach (XmlQualifiedName s in useAttributeSets)
-                                               p.ResolveAttributeSet (s).Evaluate (p);
+                                       foreach (XmlQualifiedName s in useAttributeSets) {
+                                               XslAttributeSet attset = p.ResolveAttributeSet (s);
+                                               if (attset == null)
+                                                       throw new XsltException ("Attribute set was not found.", null, p.CurrentNode);
+                                               attset.Evaluate (p);
+                                       }
 
                                if (children != null) children.Evaluate (p);
                                break;
                        case XPathNodeType.Element:
+                               bool isCData = p.InsideCDataElement;
+                               p.PushElementState (p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI, true);
                                p.Out.WriteStartElement (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI);
                                
-                               p.TryStylesheetNamespaceOutput ();
+                               p.TryStylesheetNamespaceOutput (null);
                                if (useAttributeSets != null)
                                        foreach (XmlQualifiedName s in useAttributeSets)
                                                p.ResolveAttributeSet (s).Evaluate (p);
@@ -58,15 +72,22 @@ namespace Mono.Xml.Xsl.Operations {
                                }
                        
                                if (children != null) children.Evaluate (p);
+
                                p.Out.WriteFullEndElement ();
+                               p.PopCDataState (isCData);
                                break;
                        case XPathNodeType.Attribute:
                                p.Out.WriteAttributeString (p.CurrentNode.Prefix, p.CurrentNode.LocalName, p.CurrentNode.NamespaceURI, p.CurrentNode.Value);
                                break;
                        
                        case XPathNodeType.SignificantWhitespace:
-                       case XPathNodeType.Text:
                        case XPathNodeType.Whitespace:
+                               bool cdata = p.Out.InsideCDataSection;
+                               p.Out.InsideCDataSection = false;
+                               p.Out.WriteString (p.CurrentNode.Value);
+                               p.Out.InsideCDataSection = cdata;
+                               break;
+                       case XPathNodeType.Text:
                                p.Out.WriteString (p.CurrentNode.Value);
                                break;
                        
@@ -77,7 +98,11 @@ namespace Mono.Xml.Xsl.Operations {
                        case XPathNodeType.ProcessingInstruction:
                                p.Out.WriteProcessingInstruction (p.CurrentNode.Name, p.CurrentNode.Value);
                                break;
-                       
+
+                       case XPathNodeType.Namespace:
+                               p.Out.WriteNamespaceDecl (p.CurrentNode.Name, p.CurrentNode.Value);
+                               break;
+
                        default:
                                Console.WriteLine ("unhandled node type {0}", p.CurrentNode.NodeType);
                                break;