2004-03-13 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Sat, 13 Mar 2004 15:00:28 +0000 (15:00 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Sat, 13 Mar 2004 15:00:28 +0000 (15:00 -0000)
* Compiler.cs,
  XslStylesheet.cs : Reject xsl element other than stylesheet and
  transform. Check mandatory version attribute (only for existence).

svn path=/trunk/mcs/; revision=23980

mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
mcs/class/System.XML/Mono.Xml.Xsl/Compiler.cs
mcs/class/System.XML/Mono.Xml.Xsl/XslStylesheet.cs

index a5a0b2e2195b81c10ea84ddfffd89bbf36beee07..dc92dbca1cb73057a7e78d69018f64cbdc1f5fc3 100644 (file)
@@ -1,3 +1,9 @@
+2004-03-13 Atsushi Enomoto <atsushi@ximian.com>
+
+       * Compiler.cs,
+         XslStylesheet.cs : Reject xsl element other than stylesheet and
+         transform. Check mandatory version attribute (only for existence).
+
 2004-03-07 Atsushi Enomoto <atsushi@ximian.com>
 
        * MSXslScriptManager.cs : if extension namespace was not found in
index 57960b1b2e7e77dca478e8a1fc4c3566d74ef18e..3479f2ec87d94d4fda1a980832c8ce237ca97e39 100644 (file)
@@ -112,7 +112,8 @@ namespace Mono.Xml.Xsl
                                this.res = new XmlUrlResolver ();
                        this.evidence = evidence;
 
-                       if (!nav.MoveToFirstChild ()) throw new Exception ("WTF?");
+                       if (!nav.MoveToFirstChild ())
+                               throw new XsltCompileException ("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element.", null, nav);
                                
                        outputs [""] = new XslOutput ("");
                                
index 7aefbe6859a3334d0098ac8866540244271c64b5..343d274d11a4b7efa9fedd1d9f95ad4498eef63c 100644 (file)
@@ -10,7 +10,6 @@
 //
 
 using System;
-using System.CodeDom;
 using System.Collections;
 using System.Collections.Specialized;
 using System.Xml;
@@ -121,11 +120,24 @@ namespace Mono.Xml.Xsl {
                        c.PushStylesheet (this);
                        
                        templates = new XslTemplateTable (this);
+
+                       // move to root element
+                       while (c.Input.NodeType != XPathNodeType.Element)
+                               if (!c.Input.MoveToNext ())
+                                       throw new XsltCompileException ("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element.", null, c.Input);
+
                        if (c.Input.NamespaceURI != XsltNamespace) {
                                // then it is simplified stylesheet.
                                Templates.Add (new XslTemplate (c));
                        } else {
+                               if (c.Input.LocalName != "stylesheet" &&
+                                       c.Input.LocalName != "transform")
+                                       throw new XsltCompileException ("Stylesheet root element must be either \"stylesheet\" or \"transform\" or any literal element.", null, c.Input);
+
                                version = c.Input.GetAttribute ("version", "");
+                               if (version == null)
+                                       throw new XsltCompileException ("Mandatory attribute version is missing.", null, c.Input);
+
                                extensionElementPrefixes = c.ParseQNameListAttribute ("extension-element-prefixes");
                                excludeResultPrefixes = c.ParseQNameListAttribute ("exclude-result-prefixes");
                                if (c.Input.MoveToFirstNamespace (XPathNamespaceScope.Local)) {