private void SplitUnions(Compiler compiler) { AstNode node = AstNode.NewAstNode(this.match); if (node == null) { throw new XsltException(Res.Xslt_InvalidXPath, this.match); } if (node.TypeOfAst != AstNode.QueryType.Operator) { this.priority = node.DefaultPriority; return; } while (node.TypeOfAst == AstNode.QueryType.Operator) { Operator op = (Operator)node; if (op.OperatorType != Operator.Op.UNION) { Debug.Assert(false, "Match pattern cant contain other top level operators"); break; } // We have here: UNION := UNION '|' path TemplateAction right = this.CloneWithoutName(); right.FixupMatch(compiler, op.Operand2); compiler.AddTemplate(right); node = op.Operand1; } this.FixupMatch(compiler, node); }
//TRy Changing the algorthim to simplify private static bool CalculatePriorities(Compiler compiler, AstNode node, TemplateAction right) { switch (node.TypeOfAst) { case AstNode.QueryType.Operator: Operator op = (Operator)node; if (op.OperatorType == Operator.Op.UNION) { TemplateAction left = right.Clone(); if (CalculatePriorities(compiler, op.Operand1, left)) { left.FinishClone(compiler, op.Operand1); } compiler.AddTemplate(left); if (CalculatePriorities(compiler, op.Operand2, right)) { right.FinishClone(compiler, op.Operand2); } return(false); } break; //case AstNode.QueryType.Group: // return CalculatePriorities(compiler, ((Group)node).GroupNode, right); } return(true); }
internal void CompileSingleTemplate(Compiler compiler) { NavigatorInput input = compiler.Input; // // find mandatory version attribute and launch compilation of single template // string version = null; bool wrongns = false; if (input.MoveToFirstAttribute()) { do { Debug.TraceAttribute(input); string nspace = input.NamespaceURI; string name = input.LocalName; if (Keywords.Equals(name, input.Atoms.Version)) { if (Keywords.Equals(nspace, input.Atoms.XsltNamespace)) { version = input.Value; } else { wrongns = true; } } }while(input.MoveToNextAttribute()); input.ToParent(); } if (version == null) { if (wrongns) { throw new XsltException(Res.Xslt_WrongNamespace); } throw new XsltException(Res.Xslt_MissingAttribute, Keywords.s_Version); } Debug.TraceElement(input); compiler.AddTemplate(compiler.CreateSingleTemplateAction()); }
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(); }
//TRy Changing the algorthim to simplify private static bool CalculatePriorities(Compiler compiler, AstNode node, TemplateAction right) { switch (node.TypeOfAst) { case AstNode.QueryType.Operator: Operator op = (Operator) node; if (op.OperatorType == Operator.Op.UNION) { TemplateAction left = right.Clone(); if (CalculatePriorities(compiler, op.Operand1, left)) { left.FinishClone(compiler, op.Operand1); } compiler.AddTemplate(left); if (CalculatePriorities(compiler, op.Operand2, right)) { right.FinishClone(compiler, op.Operand2); } return false; } break; //case AstNode.QueryType.Group: // return CalculatePriorities(compiler, ((Group)node).GroupNode, right); } return true; }
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(); }
internal void CompileSingleTemplate(Compiler compiler) { NavigatorInput input = compiler.Input; // // find mandatory version attribute and launch compilation of single template // string version = null; bool wrongns = false; if (input.MoveToFirstAttribute()) { do { Debug.TraceAttribute(input); string nspace = input.NamespaceURI; string name = input.LocalName; if (Keywords.Equals(name, input.Atoms.Version)) { if (Keywords.Equals(nspace, input.Atoms.XsltNamespace)) version = input.Value; else wrongns = true; } } while(input.MoveToNextAttribute()); input.ToParent(); } if (version == null) { if (wrongns) { throw new XsltException(Res.Xslt_WrongNamespace); } throw new XsltException(Res.Xslt_MissingAttribute, Keywords.s_Version); } Debug.TraceElement(input); compiler.AddTemplate(compiler.CreateSingleTemplateAction()); }