internal void AddTemplate(TemplateAction template) { Debug.Assert(template != null); Debug.Assert( ((object) this.mode == (object) template.Mode) || (template.Mode == null && this.mode.Equals(XmlQualifiedName.Empty)) || this.mode.Equals(template.Mode) ); if (this.templates == null) { this.templates = new ArrayList(); } this.templates.Add(template); }
public int Compare(object x, object y) { Debug.Assert(x != null && x is TemplateAction); Debug.Assert(y != null && y is TemplateAction); TemplateAction tx = (TemplateAction)x; TemplateAction ty = (TemplateAction)y; Debug.Assert(!double.IsNaN(tx.Priority)); Debug.Assert(!double.IsNaN(ty.Priority)); if (tx.Priority == ty.Priority) { Debug.Assert(tx.TemplateId != ty.TemplateId || tx == ty); return(tx.TemplateId - ty.TemplateId); } else { return(tx.Priority > ty.Priority ? 1 : -1); } }
private void AnalyzePriority(Compiler compiler) { NavigatorInput input = compiler.Input; if (!Double.IsNaN(this.priority) || this.matchKey == Compiler.InvalidQueryKey) { return; } // Split Unions: TheQuery theQuery = (TheQuery)compiler.QueryStore[this.MatchKey]; CompiledXpathExpr expr = (CompiledXpathExpr)theQuery.CompiledQuery; Query query = expr.QueryTree; UnionExpr union; while ((union = query as UnionExpr) != null) { Debug.Assert(!(union.qy2 is UnionExpr), "only qy1 can be union"); TemplateAction copy = this.CloneWithoutName(); compiler.QueryStore.Add(new TheQuery( new CompiledXpathExpr(union.qy2, expr.Expression, false), theQuery._ScopeManager )); copy.matchKey = compiler.QueryStore.Count - 1; copy.priority = union.qy2.XsltDefaultPriority; compiler.AddTemplate(copy); query = union.qy1; } if (expr.QueryTree != query) { // query was splitted and we need create new TheQuery for this template compiler.QueryStore[this.MatchKey] = new TheQuery( new CompiledXpathExpr(query, expr.Expression, false), theQuery._ScopeManager ); } this.priority = query.XsltDefaultPriority; }
internal override void Execute(Processor processor, ActionFrame frame) { Debug.Assert(processor != null && frame != null); switch (frame.State) { case Initialized: processor.ResetParams(); if (this.containedActions != null && this.containedActions.Count > 0) { processor.PushActionFrame(frame); frame.State = ProcessedChildren; break; } goto case ProcessedChildren; case ProcessedChildren: TemplateAction action = processor.Stylesheet.FindTemplate(this.name); if (action != null) { frame.State = ProcessedTemplate; processor.PushActionFrame(action, frame.NodeSet); break; } else { throw XsltException.Create(Res.Xslt_InvalidCallTemplate, this.name.ToString()); } case ProcessedTemplate: frame.Finished(); break; default: Debug.Fail("Invalid CallTemplateAction execution state"); break; } }
internal TemplateAction?FindTemplate(Processor processor, XPathNavigator navigator) { if (this.templates == null) { return(null); } Debug.Assert(this.templates != null); for (int templateIndex = this.templates.Count - 1; templateIndex >= 0; templateIndex--) { TemplateAction action = (TemplateAction)this.templates[templateIndex] !; int matchKey = action.MatchKey; if (matchKey != Compiler.InvalidQueryKey) { if (processor.Matches(navigator, matchKey)) { return(action); } } } return(null); }
internal void ReplaceNamespaceAlias(Compiler compiler) { if (_modeManagers != null) { IDictionaryEnumerator enumerator = _modeManagers.GetEnumerator(); while (enumerator.MoveNext()) { TemplateManager manager = (TemplateManager)enumerator.Value; if (manager.templates != null) { for (int i = 0; i < manager.templates.Count; i++) { TemplateAction template = (TemplateAction)manager.templates[i]; template.ReplaceNamespaceAlias(compiler); } } } } if (_templateNameTable != null) { IDictionaryEnumerator enumerator = _templateNameTable.GetEnumerator(); while (enumerator.MoveNext()) { TemplateAction template = (TemplateAction)enumerator.Value; template.ReplaceNamespaceAlias(compiler); } } if (_imports != null) { for (int importIndex = _imports.Count - 1; importIndex >= 0; importIndex--) { Stylesheet stylesheet = (Stylesheet)_imports[importIndex]; stylesheet.ReplaceNamespaceAlias(compiler); } } }
internal void BeginTemplate(TemplateAction template) { Debug.Assert(_currentTemplate != null); _currentTemplate = template; _currentMode = template.Mode; this.CanHaveApplyImports = template.MatchKey != Compiler.InvalidQueryKey; }
// // Template management // internal void AddTemplate(TemplateAction template) { Debug.Assert(this.stylesheet == _stylesheets.Peek()); this.stylesheet.AddTemplate(template); }
public virtual TemplateAction CreateSingleTemplateAction() { TemplateAction action = new TemplateAction(); action.CompileSingle(this); return action; }
// // Priority calculation plus template splitting // private TemplateAction CloneWithoutName() { TemplateAction clone = new TemplateAction(); { clone.containedActions = this.containedActions; clone.mode = this.mode; clone.variableCount = this.variableCount; clone.replaceNSAliasesDone = true; // We shouldn't replace NS in clones. } return clone; }
internal void AddTemplate(TemplateAction template) { XmlQualifiedName mode = template.Mode; // // Ensure template has a unique name // Debug.Assert(this.templateNameTable != null); if (template.Name != null) { if (this.templateNameTable.ContainsKey(template.Name) == false) { this.templateNameTable[template.Name] = template; } else { throw XsltException.Create(Res.Xslt_DupTemplateName, template.Name.ToString()); } } if (template.MatchKey != Compiler.InvalidQueryKey) { if (this.modeManagers == null) { this.modeManagers = new Hashtable(); } Debug.Assert(this.modeManagers != null); if (mode == null) { mode = XmlQualifiedName.Empty; } TemplateManager manager = (TemplateManager) this.modeManagers[mode]; if (manager == null) { manager = new TemplateManager(this, mode); this.modeManagers[mode] = manager; if (mode.IsEmpty) { Debug.Assert(this.templates == null); this.templates = manager; } } Debug.Assert(manager != null); template.TemplateId = ++ this.templateCount; manager.AddTemplate(template); } }