5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
9 // (C) 2003 Atsushi Enomoto
13 using System.CodeDom;
\r
14 using System.Collections;
15 using System.Collections.Specialized;
\r
17 using System.Xml.Schema;
\r
18 using System.Xml.XPath;
\r
22 using Mono.Xml.Xsl.Operations;
24 using QName = System.Xml.XmlQualifiedName;
\r
26 namespace Mono.Xml.Xsl {
\r
28 public class XslStylesheet {
\r
29 public const string XsltNamespace = "http://www.w3.org/1999/XSL/Transform";
\r
30 public const string MSXsltNamespace = "urn:schemas-microsoft-com:xslt::script";
\r
34 XslStylesheet importer;
\r
35 // Top-level elements
\r
36 ArrayList imports = new ArrayList ();
\r
37 // [QName]=>XmlSpace
\r
38 Hashtable spaceControls = new Hashtable ();
\r
39 // [string stylesheet-prefix]=>string result-prefix
\r
40 Hashtable namespaceAliases = new Hashtable ();
\r
41 // [QName]=>XmlSpace
\r
42 Hashtable parameters = new Hashtable ();
\r
44 MSXslScriptManager msScripts = new MSXslScriptManager ();
\r
45 XslTemplateTable templates;
\r
47 // stylesheet attributes
\r
49 XmlQualifiedName [] extensionElementPrefixes;
\r
50 XmlQualifiedName [] excludeResultPrefixes;
\r
51 StringDictionary stylesheetNamespaces = new StringDictionary ();
\r
53 // below are newly introduced in XSLT 2.0
\r
55 // xsl:import-schema should be interpreted into it.
\r
56 XmlSchemaCollection schemas = new XmlSchemaCollection ();
\r
57 // [QName]=>XslCharacterMap
\r
58 Hashtable characterMap = new Hashtable ();
\r
59 // [QName]=>XslDateFormat
\r
60 Hashtable dateFormats = new Hashtable ();
\r
61 // [QName]=>XslFunction
\r
62 Hashtable functions = new Hashtable ();
\r
63 // [QName]=>XslSortKey
\r
64 Hashtable sortKeys = new Hashtable ();
\r
66 string xpathDefaultNamespace = "";
\r
67 XslDefaultValidation defaultValidation = XslDefaultValidation.Lax;
\r
69 public XmlQualifiedName [] ExtensionElementPrefixes {
\r
70 get { return extensionElementPrefixes; }
\r
73 public XmlQualifiedName [] ExcludeResultPrefixes {
\r
74 get { return excludeResultPrefixes; }
\r
77 public StringDictionary StylesheetNamespaces {
\r
78 get { return stylesheetNamespaces; }
\r
81 public ArrayList Imports {
\r
82 get { return imports; }
\r
85 public Hashtable SpaceControls {
\r
86 get { return spaceControls; }
\r
89 public Hashtable NamespaceAliases {
\r
90 get { return namespaceAliases; }
\r
93 public Hashtable Parameters {
\r
94 get { return parameters; }
\r
97 public MSXslScriptManager ScriptManager{
\r
98 get { return msScripts; }
\r
101 public XslTemplateTable Templates {
\r
102 get { return templates; }
\r
106 public XslStylesheet (Compiler c)
\r
109 c.PushStylesheet (this);
111 templates = new XslTemplateTable (this);
\r
112 if (c.Input.NamespaceURI != XsltNamespace) {
\r
113 // then it is simplified stylesheet.
\r
114 Templates.Add (new XslTemplate (c));
\r
116 version = c.Input.GetAttribute ("version", "");
\r
117 extensionElementPrefixes = c.ParseQNameListAttribute ("extension-element-prefixes");
\r
118 excludeResultPrefixes = c.ParseQNameListAttribute ("exclude-result-prefixes");
\r
119 if (c.Input.MoveToFirstNamespace (XPathNamespaceScope.Local)) {
121 if (c.Input.Value == XsltNamespace)
123 this.stylesheetNamespaces.Add (c.Input.Name, c.Input.Value);
124 } while (c.Input.MoveToNextNamespace (XPathNamespaceScope.Local));
125 c.Input.MoveToParent ();
127 ProcessTopLevelElements ();
\r
130 c.PopStylesheet ();
\r
133 private XslStylesheet (Compiler c, XslStylesheet importer) : this (c)
135 this.importer = importer;
138 private void HandleInclude (string href)
140 c.PushInputDocument (href);
141 ProcessTopLevelElements ();
142 c.PopInputDocument ();
145 private void HandleImport (string href)
147 c.PushInputDocument (href);
148 imports.Add (new XslStylesheet (c, this));
149 c.PopInputDocument ();
152 private void HandleTopLevelElement ()
154 XPathNavigator n = c.Input;
155 switch (n.NamespaceURI)
162 HandleInclude (c.GetAttribute ("href"));
165 HandleImport (c.GetAttribute ("href"));
167 case "preserve-space":
168 AddSpaceControls (c.ParseQNameListAttribute ("elements"), XmlSpace.Preserve, n);
172 AddSpaceControls (c.ParseQNameListAttribute ("elements"), XmlSpace.Default, n);
175 case "namespace-alias":
176 namespaceAliases.Add (c.GetAttribute ("stylesheet-prefix", ""), c.GetAttribute ("result-prefix", ""));
179 case "attribute-set":
180 c.AddAttributeSet (new XslAttributeSet (c));
184 c.AddKeyPattern (new XslKey (c));
191 case "decimal-format":
192 c.CompileDecimalFormat ();
196 templates.Add (new XslTemplate (c));
199 c.AddGlobalVariable (new XslGlobalVariable (c));
202 c.AddGlobalVariable (new XslGlobalParam (c));
206 case MSXsltNamespace:
210 msScripts.AddScript (n);
217 private void ProcessTopLevelElements ()
\r
219 if (c.Input.MoveToFirstChild ()) {
\r
221 if (c.Input.NodeType == XPathNodeType.Element) {
222 Debug.EnterNavigator (c);
223 this.HandleTopLevelElement();
224 Debug.ExitNavigator (c);
226 } while (c.Input.MoveToNext ());
228 c.Input.MoveToParent ();
232 private void AddSpaceControls (QName [] names, XmlSpace result, XPathNavigator styleElem)
\r
234 foreach (QName name in names)
\r
235 spaceControls.Add (name, result);
\r
241 public enum XslDefaultValidation
\r