// (C) 2003 Atsushi Enomoto
//
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
using System;
-using System.CodeDom;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
namespace Mono.Xml.Xsl {
- public class XslStylesheet {
+ internal class XslStylesheet {
public const string XsltNamespace = "http://www.w3.org/1999/XSL/Transform";
public const string MSXsltNamespace = "urn:schemas-microsoft-com:xslt";
Compiler c;
- XslStylesheet importer;
+// XslStylesheet importer;
// Top-level elements
ArrayList imports = new ArrayList ();
// [QName]=>XmlSpace
XmlQualifiedName [] excludeResultPrefixes;
ArrayList stylesheetNamespaces = new ArrayList ();
- // below are newly introduced in XSLT 2.0
- // elements::
- // xsl:import-schema should be interpreted into it.
- XmlSchemaCollection schemas = new XmlSchemaCollection ();
- // [QName]=>XslCharacterMap
- Hashtable characterMap = new Hashtable ();
- // [QName]=>XslDateFormat
- Hashtable dateFormats = new Hashtable ();
- // [QName]=>XslFunction
- Hashtable functions = new Hashtable ();
- // [QName]=>XslSortKey
- Hashtable sortKeys = new Hashtable ();
- // attributes::
- string xpathDefaultNamespace = "";
- XslDefaultValidation defaultValidation = XslDefaultValidation.Lax;
-
public string BaseUri {
get { return c.Input.BaseURI; }
}
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) {
+ if (c.Input.GetAttribute ("version", XsltNamespace) == null)
+ throw new XsltCompileException ("Mandatory global attribute version is missing.", null, c.Input);
// 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)) {
XmlQualifiedName qname = new XmlQualifiedName (localName, ns);
object o = spaceControls [qname];
if (o == null) {
- foreach (XslStylesheet s in imports) {
- o = s.SpaceControls [qname];
+
+ for (int i = 0; i < imports.Count; i++) {
+ o = ((XslStylesheet) imports [i]).SpaceControls [qname];
if (o != null)
break;
}
qname = new XmlQualifiedName ("*", ns);
o = spaceControls [qname];
if (o == null) {
- foreach (XslStylesheet s in imports) {
- o = s.SpaceControls [qname];
+ for (int i = 0; i < imports.Count; i++) {
+ o = ((XslStylesheet) imports [i]).SpaceControls [qname];
if (o != null)
break;
}
qname = new XmlQualifiedName ("*", String.Empty);
o = spaceControls [qname];
if (o == null) {
- foreach (XslStylesheet s in imports) {
- o = s.SpaceControls [qname];
+ for (int i = 0; i < imports.Count; i++) {
+ o = ((XslStylesheet) imports [i]).SpaceControls [qname];
if (o != null)
break;
}
}
if (o != null) {
- XmlSpace space = (XmlSpace) o;
switch ((XmlSpace) o) {
case XmlSpace.Preserve:
return true;
string result = namespaceAliases [prefix];
if (result == null) {
- foreach (XslStylesheet s in imports) {
- result = s.namespaceAliases [prefix];
+ for (int i = 0; i < imports.Count; i++) {
+ result = ((XslStylesheet) imports [i]).namespaceAliases [prefix];
if (result != null)
break;
}
private XslStylesheet (Compiler c, XslStylesheet importer) : this (c)
{
- this.importer = importer;
+// this.importer = importer;
}
private void HandleInclude (string href)
}
- public enum XslDefaultValidation
+ internal enum XslDefaultValidation
{
Strict,
Lax,