internal static void TraceAttribute(NavigatorInput input) { #if DEBUGTRACE string s; s = String.Format("Attribute: {0}({1}):{2}={3}", new Object[] {input.Prefix, input.NamespaceURI, input.LocalName, input.Value}); System.Diagnostics.Debug.WriteLine(s, s_XsltCategory); #endif }
internal static void Trace(NavigatorInput record) { #if DEBUGTRACE string s; s = String.Format("Element: {0} ({1}) : {2}", record.Prefix, record.NamespaceURI, record.LocalName); System.Diagnostics.Debug.WriteLine(s, s_XsltCategory); #endif }
void CompileInclude(Compiler compiler) { string href = compiler.GetSingleAttribute(compiler.Input.Atoms.Href); Debug.WriteLine("Including document: + \"" + href + "\""); NavigatorInput input = compiler.ResolveDocument(href); compiler.PushInputDocument(input, input.Href); Debug.TraceElement(compiler.Input); try { // Bug.Bug. We have to push stilesheet here. Otherwise document("") will not work properly. // Not shure now. Probebly I fixed this problem in different place. Reinvestigate. CompileDocument(compiler, /*inInclude*/ true); } catch (Exception e) { throw new XsltCompileException(e, input.BaseURI, input.LineNumber, input.LinePosition); } finally { compiler.PopInputDocument(); } }
internal void PopInputDocument() { Debug.Assert(this.input != null); Debug.Assert(this.input.Atoms == this.atoms); NavigatorInput lastInput = this.input; this.input = lastInput.Next; lastInput.Next = null; if (this.input != null) { this.atoms = this.input.Atoms; this.scopeManager = this.input.InputScopeManager; } else { this.atoms = null; this.scopeManager = null; } RemoveDocumentURI(lastInput.Href); lastInput.Close(); }
public void CompileAttributes(Compiler compiler) { NavigatorInput input = compiler.Input; string element = input.LocalName; if (input.MoveToFirstAttribute()) { do { Debug.TraceAttribute(input); if (!Keywords.Equals(input.NamespaceURI, input.Atoms.Empty)) { continue; } try { if (CompileAttribute(compiler) == false) { throw XsltException.InvalidAttribute(element, input.LocalName); } }catch (Exception) { if (!compiler.ForwardCompatibility) { throw; } else { // In ForwardCompatibility mode we ignoreing all unknown or incorrect attributes // If it's mandatory attribute we'l notice it absents later. } } }while (input.MoveToNextAttribute()); input.ToParent(); } }
void CompileInstruction(Compiler compiler) { NavigatorInput input = compiler.Input; CompiledAction action = null; Debug.Assert(Keywords.Equals(input.NamespaceURI, input.Atoms.XsltNamespace)); string name = input.LocalName; if (Keywords.Equals(name, input.Atoms.ApplyImports)) { action = compiler.CreateApplyImportsAction(); } else if (Keywords.Equals(name, input.Atoms.ApplyTemplates)) { action = compiler.CreateApplyTemplatesAction(); } else if (Keywords.Equals(name, input.Atoms.Attribute)) { action = compiler.CreateAttributeAction(); } else if (Keywords.Equals(name, input.Atoms.CallTemplate)) { action = compiler.CreateCallTemplateAction(); } else if (Keywords.Equals(name, input.Atoms.Choose)) { action = compiler.CreateChooseAction(); } else if (Keywords.Equals(name, input.Atoms.Comment)) { action = compiler.CreateCommentAction(); } else if (Keywords.Equals(name, input.Atoms.Copy)) { action = compiler.CreateCopyAction(); } else if (Keywords.Equals(name, input.Atoms.CopyOf)) { action = compiler.CreateCopyOfAction(); } else if (Keywords.Equals(name, input.Atoms.Element)) { action = compiler.CreateElementAction(); } else if (Keywords.Equals(name, input.Atoms.Fallback)) { return; } else if (Keywords.Equals(name, input.Atoms.ForEach)) { action = compiler.CreateForEachAction(); } else if (Keywords.Equals(name, input.Atoms.If)) { action = compiler.CreateIfAction(IfAction.ConditionType.ConditionIf); } else if (Keywords.Equals(name, input.Atoms.Message)) { action = compiler.CreateMessageAction(); } else if (Keywords.Equals(name, input.Atoms.Number)) { action = compiler.CreateNumberAction(); } else if (Keywords.Equals(name, input.Atoms.ProcessingInstruction)) { action = compiler.CreateProcessingInstructionAction(); } else if (Keywords.Equals(name, input.Atoms.Text)) { action = compiler.CreateTextAction(); } else if (Keywords.Equals(name, input.Atoms.ValueOf)) { action = compiler.CreateValueOfAction(); } else if (Keywords.Equals(name, input.Atoms.Variable)) { action = compiler.CreateVariableAction(VariableType.LocalVariable); } else { if (compiler.ForwardCompatibility) { action = compiler.CreateNewInstructionAction(); } else { throw XsltException.UnexpectedKeyword(compiler); } } Debug.Assert(action != null); AddAction(action); }
internal void CompileStylesheetAttributes(Compiler compiler) { NavigatorInput input = compiler.Input; string element = input.LocalName; string badAttribute = null; string version = null; if (input.MoveToFirstAttribute()) { do { Debug.TraceAttribute(input); string nspace = input.NamespaceURI; string name = input.LocalName; if (!Keywords.Equals(nspace, input.Atoms.Empty)) { continue; } Debug.WriteLine("Attribute name: \"" + name + "\""); if (Keywords.Equals(name, input.Atoms.Version)) { version = input.Value; if (1 <= XmlConvert.ToXPathDouble(version)) { compiler.ForwardCompatibility = (version != Keywords.s_Version10); } else { // XmlConvert.ToXPathDouble(version) an be NaN! if (!compiler.ForwardCompatibility) { throw XsltException.InvalidAttrValue(Keywords.s_Version, version); } } Debug.WriteLine("Version found: \"" + version + "\""); } else if (Keywords.Equals(name, input.Atoms.ExtensionElementPrefixes)) { compiler.InsertExtensionNamespace(input.Value); } else if (Keywords.Equals(name, input.Atoms.ExcludeResultPrefixes)) { compiler.InsertExcludedNamespace(input.Value); } else if (Keywords.Equals(name, input.Atoms.Id)) { // Do nothing here. } else { // We can have version atribute later. For now remember this attribute and continue badAttribute = name; } }while(input.MoveToNextAttribute()); input.ToParent(); } if (version == null) { throw new XsltException(Res.Xslt_MissingAttribute, Keywords.s_Version); } if (badAttribute != null && !compiler.ForwardCompatibility) { throw XsltException.InvalidAttribute(element, badAttribute); } }
protected void CompileTopLevelElements(Compiler compiler) { // Navigator positioned at parent root, need to move to child and then back if (compiler.Recurse() == false) { Debug.WriteLine("Nothing to compile, exiting"); return; } NavigatorInput input = compiler.Input; bool notFirstElement = false; do { Debug.Trace(input); switch (input.NodeType) { case XPathNodeType.Element: string name = input.LocalName; string nspace = input.NamespaceURI; if (Keywords.Equals(nspace, input.Atoms.XsltNamespace)) { if (Keywords.Equals(name, input.Atoms.Import)) { if (notFirstElement) { throw new XsltException(Res.Xslt_NotFirstImport); } // We should compile imports in reverse order after all toplevel elements. // remember it now and return to it in CompileImpoorts(); compiler.CompiledStylesheet.Imports.Add(compiler.GetSingleAttribute(compiler.Input.Atoms.Href)); } else if (Keywords.Equals(name, input.Atoms.Include)) { notFirstElement = true; CompileInclude(compiler); } else { notFirstElement = true; compiler.PushNamespaceScope(); if (Keywords.Equals(name, input.Atoms.StripSpace)) { CompileSpace(compiler, false); } else if (Keywords.Equals(name, input.Atoms.PreserveSpace)) { CompileSpace(compiler, true); } else if (Keywords.Equals(name, input.Atoms.Output)) { CompileOutput(compiler); } else if (Keywords.Equals(name, input.Atoms.Key)) { CompileKey(compiler); } else if (Keywords.Equals(name, input.Atoms.DecimalFormat)) { CompileDecimalFormat(compiler); } else if (Keywords.Equals(name, input.Atoms.NamespaceAlias)) { CompileNamespaceAlias(compiler); } else if (Keywords.Equals(name, input.Atoms.AttributeSet)) { compiler.AddAttributeSet(compiler.CreateAttributeSetAction()); } else if (Keywords.Equals(name, input.Atoms.Variable)) { VariableAction action = compiler.CreateVariableAction(VariableType.GlobalVariable); if (action != null) { AddAction(action); } } else if (Keywords.Equals(name, input.Atoms.Param)) { VariableAction action = compiler.CreateVariableAction(VariableType.GlobalParameter); if (action != null) { AddAction(action); } } else if (Keywords.Equals(name, input.Atoms.Template)) { compiler.AddTemplate(compiler.CreateTemplateAction()); } else { if (!compiler.ForwardCompatibility) { throw XsltException.UnexpectedKeyword(compiler); } } compiler.PopScope(); } } else if (nspace == input.Atoms.MsXsltNamespace && name == input.Atoms.Script) { AddScript(compiler); } else { if (Keywords.Equals(nspace, input.Atoms.Empty)) { throw new XsltException(Res.Xslt_NullNsAtTopLevel, input.Name); } // Ignoring non-recognized namespace per XSLT spec 2.2 } break; case XPathNodeType.ProcessingInstruction: case XPathNodeType.Comment: case XPathNodeType.Whitespace: case XPathNodeType.SignificantWhitespace: break; default: throw new XsltException(Res.Xslt_InvalidContents, "xsl:stylesheet"); } }while (compiler.Advance()); compiler.ToParent(); }
protected void CompileDecimalFormat(Compiler compiler) { NumberFormatInfo info = new NumberFormatInfo(); DecimalFormat format = new DecimalFormat(info, '#', '0', ';'); XmlQualifiedName Name = null; NavigatorInput input = compiler.Input; if (input.MoveToFirstAttribute()) { do { Debug.TraceAttribute(input); if (!Keywords.Equals(input.Prefix, input.Atoms.Empty)) { continue; } string name = input.LocalName; string value = input.Value; if (Keywords.Equals(name, input.Atoms.Name)) { Name = compiler.CreateXPathQName(value); } else if (Keywords.Equals(name, input.Atoms.DecimalSeparator)) { info.NumberDecimalSeparator = value; } else if (Keywords.Equals(name, input.Atoms.GroupingSeparator)) { info.NumberGroupSeparator = value; } else if (Keywords.Equals(name, input.Atoms.Infinity)) { info.PositiveInfinitySymbol = value; } else if (Keywords.Equals(name, input.Atoms.MinusSign)) { info.NegativeSign = value; } else if (Keywords.Equals(name, input.Atoms.NaN)) { info.NaNSymbol = value; } else if (Keywords.Equals(name, input.Atoms.Percent)) { info.PercentSymbol = value; } else if (Keywords.Equals(name, input.Atoms.PerMille)) { info.PerMilleSymbol = value; } else if (Keywords.Equals(name, input.Atoms.Digit)) { if (CheckAttribute(value.Length == 1, compiler)) { format.digit = value[0]; } } else if (Keywords.Equals(name, input.Atoms.ZeroDigit)) { if (CheckAttribute(value.Length == 1, compiler)) { format.zeroDigit = value[0]; } } else if (Keywords.Equals(name, input.Atoms.PatternSeparator)) { if (CheckAttribute(value.Length == 1, compiler)) { format.patternSeparator = value[0]; } } }while(input.MoveToNextAttribute()); info.NegativeInfinitySymbol = String.Concat(info.NegativeSign, info.PositiveInfinitySymbol); if (Name == null) { Name = new XmlQualifiedName(null, null); } compiler.AddDecimalFormat(Name, format); input.ToParent(); } }
internal void PushInputDocument(NavigatorInput newInput, string inputUri) { Debug.Assert(newInput != null); Debug.WriteLine("Pushing document \"" + inputUri + "\""); AddDocumentURI(inputUri); newInput.Next = this.input; this.input = newInput; this.atoms = this.input.Atoms; this.scopeManager = this.input.InputScopeManager; }
// // The World of Compile // internal void Compile(NavigatorInput input, XmlResolver xmlResolver) { Debug.Assert(this.input == null && this.atoms == null); this.xmlResolver = xmlResolver == null ? new XmlUrlResolver() : xmlResolver; PushInputDocument(input, input.BaseURI); this.rootScope = this.scopeManager.PushScope(); this.queryStore = new ArrayList(); AddSpecialQueries(); try { this.rootStylesheet = new Stylesheet(); PushStylesheet(this.rootStylesheet); Debug.Assert(this.input != null && this.atoms != null); try { this.CreateRootAction(); } catch(Exception e) { throw new XsltCompileException(e, this.Input.BaseURI, this.Input.LineNumber, this.Input.LinePosition); } this.stylesheet.ProcessTemplates(); this.rootAction.PorcessAttributeSets(this.rootStylesheet); this.stylesheet.SortWhiteSpace(); CompileScript(); this.rootAction.SortVariables(); if (this.globalNamespaceAliasTable != null ) { this.stylesheet.ReplaceNamespaceAlias(this); this.rootAction.ReplaceNamespaceAlias(this); } } finally { PopInputDocument(); } Debug.Assert(this.rootAction != null); Debug.Assert(this.stylesheet != null); Debug.Assert(this.queryStore != null); Debug.Assert(this.input == null && this.atoms == null); }
private void Compile(XPathNavigator stylesheet, XmlResolver resolver) { Debug.CompilingMessage(); Compiler compiler = (Debugger == null) ? new Compiler() : new DbgCompiler(this.Debugger); NavigatorInput input = new NavigatorInput(stylesheet); compiler.Compile(input, resolver); StoreCompiledStylesheet(compiler.CompiledStylesheet, compiler.QueryStore, compiler.RootAction); TraceCompiledState(compiler); }
// // Constructor // internal NavigatorInput(XPathNavigator navigator, string baseUri, InputScope rootScope) { if (navigator == null) { throw new ArgumentNullException("navigator"); } if (baseUri == null) { throw new ArgumentNullException("baseUri"); } Debug.Assert(navigator.NameTable != null); _Next = null; _Href = baseUri; _Atoms = new Keywords(navigator.NameTable); _Atoms.LookupKeywords(); _Navigator = navigator; _Manager = new InputScopeManager(_Navigator, rootScope); _PositionInfo = PositionInfo.GetPositionInfo(_Navigator); /*BeginReading:*/ AssertInput(); if (NodeType == XPathNodeType.Root) { _Navigator.MoveToFirstChild(); } }
internal static void TraceElement(NavigatorInput input) { #if DEBUGTRACE System.Diagnostics.Debug.WriteLine("=============== Element trace ==================", s_XsltCategory); Trace(input); if (input.MoveToFirstAttribute()) { do { TraceAttribute(input); } while (input.MoveToNextAttribute()); input.ToParent(); } #endif }
public NamespaceEvent(NavigatorInput input) { Debug.Assert(input != null); Debug.Assert(input.NodeType == XPathNodeType.Namespace); this.namespaceUri = input.Value; this.name = input.LocalName; }