public void Process(XPathNavigator root, Outputter outputtter, XsltArgumentList args, XmlResolver resolver) { this.args = args; this.root = root; this.resolver = ((resolver == null) ? new XmlUrlResolver() : resolver); this.currentOutputUri = string.Empty; this.PushNodeset(new SelfIterator(root, this.XPathContext)); this.CurrentNodeset.MoveNext(); if (args != null) { foreach (object obj in this.CompiledStyle.Variables.Values) { XslGlobalVariable xslGlobalVariable = (XslGlobalVariable)obj; if (xslGlobalVariable is XslGlobalParam) { object param = args.GetParam(xslGlobalVariable.Name.Name, xslGlobalVariable.Name.Namespace); if (param != null) { ((XslGlobalParam)xslGlobalVariable).Override(this, param); } xslGlobalVariable.Evaluate(this); } } } foreach (object obj2 in this.CompiledStyle.Variables.Values) { XslGlobalVariable xslGlobalVariable2 = (XslGlobalVariable)obj2; if (args == null || !(xslGlobalVariable2 is XslGlobalParam)) { xslGlobalVariable2.Evaluate(this); } } this.PopNodeset(); this.PushOutput(outputtter); this.ApplyTemplates(new SelfIterator(root, this.XPathContext), XmlQualifiedName.Empty, null); this.PopOutput(); }
private void HandleTopLevelElement(Compiler c) { XPathNavigator n = c.Input; switch (n.NamespaceURI) { case XsltNamespace: switch (n.LocalName) { case "include": HandleInclude(c); break; case "preserve-space": AddSpaceControls(c.ParseQNameListAttribute("elements"), XmlSpace.Preserve, n); break; case "strip-space": AddSpaceControls(c.ParseQNameListAttribute("elements"), XmlSpace.Default, n); break; case "namespace-alias": // do nothing. It is handled in prior. break; case "attribute-set": c.AddAttributeSet(new XslAttributeSet(c)); break; case "key": XslKey key = new XslKey(c); if (keys [key.Name] == null) { keys [key.Name] = new ArrayList(); } ((ArrayList)keys [key.Name]).Add(key); break; case "output": c.CompileOutput(); break; case "decimal-format": c.CompileDecimalFormat(); break; case "template": templates.Add(new XslTemplate(c)); break; case "variable": XslGlobalVariable gvar = new XslGlobalVariable(c); variables [gvar.Name] = gvar; break; case "param": XslGlobalParam gpar = new XslGlobalParam(c); variables [gpar.Name] = gpar; break; default: if (version == "1.0") { throw new XsltCompileException("Unrecognized top level element after imports", null, c.Input); } break; } break; case MSXsltNamespace: switch (n.LocalName) { case "script": c.ScriptManager.AddScript(c); break; } break; } }
public void AddGlobalVariable(XslGlobalVariable var) { globalVariables [var.Name] = var; }
private void HandleTopLevelElement(Compiler c) { XPathNavigator input = c.Input; string namespaceURI = input.NamespaceURI; if (namespaceURI != null) { if (XslStylesheet.< > f__switch$map26 == null) { XslStylesheet.< > f__switch$map26 = new Dictionary <string, int>(2) { { "http://www.w3.org/1999/XSL/Transform", 0 }, { "urn:schemas-microsoft-com:xslt", 1 } }; } int num; if (XslStylesheet.< > f__switch$map26.TryGetValue(namespaceURI, out num)) { if (num != 0) { if (num == 1) { string localName = input.LocalName; if (localName != null) { if (XslStylesheet.< > f__switch$map25 == null) { XslStylesheet.< > f__switch$map25 = new Dictionary <string, int>(1) { { "script", 0 } }; } int num2; if (XslStylesheet.< > f__switch$map25.TryGetValue(localName, out num2)) { if (num2 == 0) { c.ScriptManager.AddScript(c); } } } } } else { string localName = input.LocalName; switch (localName) { case "include": this.HandleInclude(c); goto IL_2B0; case "preserve-space": this.AddSpaceControls(c.ParseQNameListAttribute("elements"), XmlSpace.Preserve, input); goto IL_2B0; case "strip-space": this.AddSpaceControls(c.ParseQNameListAttribute("elements"), XmlSpace.Default, input); goto IL_2B0; case "namespace-alias": goto IL_2B0; case "attribute-set": c.AddAttributeSet(new XslAttributeSet(c)); goto IL_2B0; case "key": { XslKey xslKey = new XslKey(c); if (this.keys[xslKey.Name] == null) { this.keys[xslKey.Name] = new ArrayList(); } ((ArrayList)this.keys[xslKey.Name]).Add(xslKey); goto IL_2B0; } case "output": c.CompileOutput(); goto IL_2B0; case "decimal-format": c.CompileDecimalFormat(); goto IL_2B0; case "template": this.templates.Add(new XslTemplate(c)); goto IL_2B0; case "variable": { XslGlobalVariable xslGlobalVariable = new XslGlobalVariable(c); this.variables[xslGlobalVariable.Name] = xslGlobalVariable; goto IL_2B0; } case "param": { XslGlobalParam xslGlobalParam = new XslGlobalParam(c); this.variables[xslGlobalParam.Name] = xslGlobalParam; goto IL_2B0; } } if (this.version == "1.0") { throw new XsltCompileException("Unrecognized top level element after imports", null, c.Input); } IL_2B0 :; } } } }
internal void Compile(Compiler c) { c.PushStylesheet(this); this.templates = new XslTemplateTable(this); this.baseURI = c.Input.BaseURI; 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 != "http://www.w3.org/1999/XSL/Transform") { if (c.Input.GetAttribute("version", "http://www.w3.org/1999/XSL/Transform") == string.Empty) { throw new XsltCompileException("Mandatory global attribute version is missing", null, c.Input); } this.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); } this.version = c.Input.GetAttribute("version", string.Empty); if (this.version == string.Empty) { throw new XsltCompileException("Mandatory attribute version is missing", null, c.Input); } this.extensionElementPrefixes = this.ParseMappedPrefixes(c.GetAttribute("extension-element-prefixes"), c.Input); this.excludeResultPrefixes = this.ParseMappedPrefixes(c.GetAttribute("exclude-result-prefixes"), c.Input); if (c.Input.MoveToFirstNamespace(XPathNamespaceScope.Local)) { do { if (!(c.Input.Value == "http://www.w3.org/1999/XSL/Transform")) { this.stylesheetNamespaces.Insert(0, new XmlQualifiedName(c.Input.Name, c.Input.Value)); } }while (c.Input.MoveToNextNamespace(XPathNamespaceScope.Local)); c.Input.MoveToParent(); } this.ProcessTopLevelElements(c); } foreach (object obj in this.variables.Values) { XslGlobalVariable var = (XslGlobalVariable)obj; c.AddGlobalVariable(var); } foreach (object obj2 in this.keys.Values) { ArrayList arrayList = (ArrayList)obj2; for (int i = 0; i < arrayList.Count; i++) { c.AddKey((XslKey)arrayList[i]); } } c.PopStylesheet(); this.inProcessIncludes = null; }