internal void CompileKey(Compiler compiler) { NavigatorInput input = compiler.Input; string element = input.LocalName; int MatchKey = Compiler.InvalidQueryKey; int UseKey = Compiler.InvalidQueryKey; XmlQualifiedName Name = null; if (input.MoveToFirstAttribute()) { do { string nspace = input.NamespaceURI; string name = input.LocalName; string value = input.Value; if (nspace.Length != 0) { continue; } if (Ref.Equal(name, input.Atoms.Name)) { Name = compiler.CreateXPathQName(value); } else if (Ref.Equal(name, input.Atoms.Match)) { MatchKey = compiler.AddQuery(value, /*allowVars:*/ false, /*allowKey*/ false, /*pattern*/ true); } else if (Ref.Equal(name, input.Atoms.Use)) { UseKey = compiler.AddQuery(value, /*allowVars:*/ false, /*allowKey*/ false, /*pattern*/ false); } else { if (!compiler.ForwardCompatibility) { throw XsltException.Create(Res.Xslt_InvalidAttribute, name, element); } } }while(input.MoveToNextAttribute()); input.ToParent(); } CheckRequiredAttribute(compiler, MatchKey != Compiler.InvalidQueryKey, "match"); CheckRequiredAttribute(compiler, UseKey != Compiler.InvalidQueryKey, "use"); CheckRequiredAttribute(compiler, Name != null, "name"); // It is a breaking change to check for emptiness, SQLBUDT 324364 //CheckEmpty(compiler); compiler.InsertKey(Name, MatchKey, UseKey); }
// --------------------------- XsltContext ------------------- // Resolving variables and functions public override IXsltContextVariable ResolveVariable(string prefix, string name) { string namespaceURI = this.LookupNamespace(prefix); XmlQualifiedName qname = new XmlQualifiedName(name, namespaceURI); IXsltContextVariable variable = _manager.VariableScope.ResolveVariable(qname); if (variable == null) { throw XsltException.Create(SR.Xslt_InvalidVariable, qname.ToString()); } return(variable); }
private string ParseLetter(string letter) { if (letter == null || letter == "traditional" || letter == "alphabetic") { return(letter); } if (!this.forwardCompatibility) { throw XsltException.Create(Res.Xslt_InvalidAttrValue, "letter-value", letter); } return(null); }
internal void CompileKey(Compiler compiler) { NavigatorInput input = compiler.Input; string element = input.LocalName; int MatchKey = Compiler.InvalidQueryKey; int UseKey = Compiler.InvalidQueryKey; XmlQualifiedName Name = null; if (input.MoveToFirstAttribute()) { do { string nspace = input.NamespaceURI; string name = input.LocalName; string value = input.Value; if (!Keywords.Equals(nspace, input.Atoms.Empty)) { continue; } if (Keywords.Equals(name, input.Atoms.Name)) { Name = compiler.CreateXPathQName(value); } else if (Keywords.Equals(name, input.Atoms.Match)) { MatchKey = compiler.AddQuery(value, /*allowVars:*/ false, /*allowKey*/ false, /*pattern*/ true); } else if (Keywords.Equals(name, input.Atoms.Use)) { UseKey = compiler.AddQuery(value, /*allowVars:*/ false, /*allowKey*/ false, /*pattern*/ false); } else { if (!compiler.ForwardCompatibility) { throw XsltException.Create(Res.Xslt_InvalidAttribute, name, element); } } }while(input.MoveToNextAttribute()); input.ToParent(); } CheckRequiredAttribute(compiler, MatchKey != Compiler.InvalidQueryKey, Keywords.s_Match); CheckRequiredAttribute(compiler, UseKey != Compiler.InvalidQueryKey, Keywords.s_Use); CheckRequiredAttribute(compiler, Name != null, Keywords.s_Name); compiler.InsertKey(Name, MatchKey, UseKey); }
internal bool GetYesNo(string value) { Debug.Assert(value != null); Debug.Assert((object)value == (object)Input.Value); // this is always true. Why we passing value to this function. if (value == "yes") { return(true); } if (value == "no") { return(false); } throw XsltException.Create(SR.Xslt_InvalidAttrValue, Input.LocalName, value); }
internal void CheckDuplicateParams(XmlQualifiedName name) { if (this.containedActions != null) { foreach (CompiledAction action in this.containedActions) { WithParamAction?param = action as WithParamAction; if (param != null && param.Name == name) { throw XsltException.Create(SR.Xslt_DuplicateWithParam, name.ToString()); } } } }
internal bool Matches(XPathNavigator context, int key) { // We don't use XPathNavigator.Matches() to avoid cloning of Query on each call Query query = this.GetValueQuery(key, GetMatchesContext()); try { bool result = query.MatchNode(context) != null; RecycleMatchesContext(); return(result); } catch (XPathException) { throw XsltException.Create(Res.Xslt_InvalidPattern, this.GetQueryExpression(key)); } }
internal override void Compile(Compiler compiler) { CompileAttributes(compiler); CheckRequiredAttribute(compiler, this.name, "name"); if (compiler.Recurse()) { CompileTemplate(compiler); compiler.ToParent(); if (this.selectKey != Compiler.InvalidQueryKey && this.containedActions != null) { throw XsltException.Create(SR.Xslt_VariableCntSel2, this.nameStr); } } }
internal void AddTemplate(TemplateAction template) { XmlQualifiedName?mode = template.Mode; // // Ensure template has a unique name // Debug.Assert(_templateNameTable != null); if (template.Name != null) { if (_templateNameTable.ContainsKey(template.Name) == false) { _templateNameTable[template.Name] = template; } else { throw XsltException.Create(SR.Xslt_DupTemplateName, template.Name.ToString()); } } if (template.MatchKey != Compiler.InvalidQueryKey) { _modeManagers ??= new Hashtable(); mode ??= XmlQualifiedName.Empty; TemplateManager?manager = (TemplateManager?)_modeManagers[mode]; if (manager == null) { manager = new TemplateManager(this, mode); _modeManagers[mode] = manager; if (mode.IsEmpty) { Debug.Assert(_templates == null); _templates = manager; } } Debug.Assert(manager != null); template.TemplateId = ++_templateCount; manager.AddTemplate(template); } }
private static PrefixQName?CreateAttributeQName(string name, string?nsUri, InputScopeManager?manager) { // if name == "xmlns" we don't need to generate this attribute. // to avoid its generation we can return false and not add AttributeCreation to it's parent container action // for now not creating this.qname will do the trick at execution time if (name == "xmlns") { return(null); } if (nsUri == XmlReservedNs.NsXmlNs) { throw XsltException.Create(SR.Xslt_ReservedNS, nsUri); } PrefixQName qname = new PrefixQName(); qname.SetQName(name); qname.Namespace = nsUri != null ? nsUri : manager !.ResolveXPathNamespace(qname.Prefix); if (qname.Prefix.StartsWith("xml", StringComparison.Ordinal)) { if (qname.Prefix.Length == 3) { // prefix == "xml" if (qname.Namespace == XmlReservedNs.NsXml && (qname.Name == "lang" || qname.Name == "space")) { // preserve prefix for xml:lang and xml:space } else { qname.ClearPrefix(); } } else if (qname.Prefix == "xmlns") { if (qname.Namespace == XmlReservedNs.NsXmlNs) { // if NS wasn't specified we have to use prefix to find it and this is imposible for 'xmlns' throw XsltException.Create(SR.Xslt_InvalidPrefix, qname.Prefix); } else { qname.ClearPrefix(); } } } return(qname); }
internal bool GetYesNo(string value) { Debug.Assert(value != null); Debug.Assert((object)value == (object)Input.Value); // this is always true. Why we passing value to this function. // if (value == null) // return false; // in XSLT it happens that default value was always false; if (value.Equals(Atoms.Yes)) { return(true); } if (value.Equals(Atoms.No)) { return(false); } throw XsltException.Create(Res.Xslt_InvalidAttrValue, Input.LocalName, value); }
internal override void Compile(Compiler compiler) { CompileAttributes(compiler); CheckEmpty(compiler); this.forwardCompatibility = compiler.ForwardCompatibility; this.formatTokens = ParseFormat(PrecalculateAvt(ref this.formatAvt)); this.letter = ParseLetter(PrecalculateAvt(ref this.letterAvt)); this.lang = PrecalculateAvt(ref this.langAvt); this.groupingSep = PrecalculateAvt(ref this.groupingSepAvt); if (this.groupingSep != null && this.groupingSep.Length > 1) { throw XsltException.Create(Res.Xslt_CharAttribute, Keywords.s_GroupingSeparator); } this.groupingSize = PrecalculateAvt(ref this.groupingSizeAvt); }
private string ParseLang(string value) { if (value == null) // Avt is not constant, or attribute wasn't defined { return(null); } if (!XmlComplianceUtil.IsValidLanguageID(value.ToCharArray(), 0, value.Length)) { if (this.forwardCompatibility) { return(null); } throw XsltException.Create(Res.Xslt_InvalidAttrValue, Keywords.s_Lang, value); } return(value); }
internal override void Compile(Compiler compiler) { CompileAttributes(compiler); CheckEmpty(compiler); _forwardCompatibility = compiler.ForwardCompatibility; _formatTokens = ParseFormat(PrecalculateAvt(ref _formatAvt)); _letter = ParseLetter(PrecalculateAvt(ref _letterAvt)); _lang = PrecalculateAvt(ref _langAvt); _groupingSep = PrecalculateAvt(ref _groupingSepAvt); if (_groupingSep != null && _groupingSep.Length > 1) { throw XsltException.Create(SR.Xslt_CharAttribute, "grouping-separator"); } _groupingSize = PrecalculateAvt(ref _groupingSizeAvt); }
internal void CompileNamespaceAlias(Compiler compiler) { NavigatorInput input = compiler.Input; string element = input.LocalName; string? namespace1 = null, namespace2 = null; string? prefix1 = null, prefix2 = null; if (input.MoveToFirstAttribute()) { do { string nspace = input.NamespaceURI; string name = input.LocalName; if (nspace.Length != 0) { continue; } if (Ref.Equal(name, input.Atoms.StylesheetPrefix)) { prefix1 = input.Value; namespace1 = compiler.GetNsAlias(ref prefix1); } else if (Ref.Equal(name, input.Atoms.ResultPrefix)) { prefix2 = input.Value; namespace2 = compiler.GetNsAlias(ref prefix2); } else { if (!compiler.ForwardCompatibility) { throw XsltException.Create(SR.Xslt_InvalidAttribute, name, element); } } }while (input.MoveToNextAttribute()); input.ToParent(); } CheckRequiredAttribute(compiler, namespace1, "stylesheet-prefix"); CheckRequiredAttribute(compiler, namespace2, "result-prefix"); CheckEmpty(compiler); //String[] resultarray = { prefix2, namespace2 }; compiler.AddNamespaceAlias(namespace1 !, new NamespaceInfo(prefix2, namespace2, compiler.Stylesheetid)); }
internal void AddScript(string source, ScriptingLanguage lang, string ns, string fileName, int lineNumber) { ValidateExtensionNamespace(ns); for (ScriptingLanguage langTmp = ScriptingLanguage.JScript; langTmp <= ScriptingLanguage.CSharp; langTmp++) { Hashtable typeDecls = _typeDeclsByLang[(int)langTmp]; if (lang == langTmp) { throw new PlatformNotSupportedException(SR.CompilingScriptsNotSupported); } else if (typeDecls.Contains(ns)) { throw XsltException.Create(SR.Xslt_ScriptMixedLanguages, ns); } } }
internal override bool CompileAttribute(Compiler compiler) { string name = compiler.Input.LocalName; string value = compiler.Input.Value; if (Ref.Equal(name, compiler.Atoms.Match)) { Debug.Assert(_matchKey == Compiler.InvalidQueryKey); _matchKey = compiler.AddQuery(value, /*allowVars:*/ false, /*allowKey:*/ true, /*pattern*/ true); } else if (Ref.Equal(name, compiler.Atoms.Name)) { Debug.Assert(_name == null); _name = compiler.CreateXPathQName(value); } else if (Ref.Equal(name, compiler.Atoms.Priority)) { Debug.Assert(double.IsNaN(_priority)); _priority = XmlConvert.ToXPathDouble(value); if (double.IsNaN(_priority) && !compiler.ForwardCompatibility) { throw XsltException.Create(SR.Xslt_InvalidAttrValue, "priority", value); } } else if (Ref.Equal(name, compiler.Atoms.Mode)) { Debug.Assert(_mode == null); if (compiler.AllowBuiltInMode && value == "*") { _mode = Compiler.BuiltInMode; } else { _mode = compiler.CreateXPathQName(value); } } else { return(false); } return(true); }
internal object EvaluateVariable(VariableAction variable) { Object result = this.processor.GetVariableValue(variable); if (result == null && !variable.IsGlobal) { // This was uninitialized local variable. May be we have sutable global var too? VariableAction global = this.manager.VariableScope.ResolveGlobalVariable(variable.Name); if (global != null) { result = this.processor.GetVariableValue(global); } } if (result == null) { throw XsltException.Create(Res.Xslt_InvalidVariable, variable.Name.ToString()); } return(result); }
private void CompileContent(Compiler compiler) { NavigatorInput input = compiler.Input; if (compiler.Recurse()) { do { switch (input.NodeType) { case XPathNodeType.Element: compiler.PushNamespaceScope(); string nspace = input.NamespaceURI; string name = input.LocalName; if (Keywords.Equals(nspace, input.Atoms.XsltNamespace) && Keywords.Equals(name, input.Atoms.Attribute)) { // found attribute so add it AddAction(compiler.CreateAttributeAction()); } else { throw compiler.UnexpectedKeyword(); } compiler.PopScope(); break; case XPathNodeType.Comment: case XPathNodeType.ProcessingInstruction: case XPathNodeType.Whitespace: case XPathNodeType.SignificantWhitespace: break; default: throw XsltException.Create(Res.Xslt_InvalidContents, Keywords.s_AttributeSet); } }while(compiler.Advance()); compiler.ToParent(); } }
private void CompileContent(Compiler compiler) { NavigatorInput input = compiler.Input; if (compiler.Recurse()) { do { switch (input.NodeType) { case XPathNodeType.Element: compiler.PushNamespaceScope(); string nspace = input.NamespaceURI; string name = input.LocalName; if (Keywords.Equals(nspace, input.Atoms.XsltNamespace) && Keywords.Equals(name, input.Atoms.WithParam)) { WithParamAction par = compiler.CreateWithParamAction(); CheckDuplicateParams(par.Name); AddAction(par); } else { throw compiler.UnexpectedKeyword(); } compiler.PopScope(); break; case XPathNodeType.Comment: case XPathNodeType.ProcessingInstruction: case XPathNodeType.Whitespace: case XPathNodeType.SignificantWhitespace: break; default: throw XsltException.Create(Res.Xslt_InvalidContents, Keywords.s_CallTemplate); } } while(compiler.Advance()); compiler.ToParent(); } }
private XmlCaseOrder ParseCaseOrder(string value) { if (value == null) { // Avt is not constant, or attribute wasn't defined return(XmlCaseOrder.None); } if (value == "upper-first") { return(XmlCaseOrder.UpperFirst); } if (value == "lower-first") { return(XmlCaseOrder.LowerFirst); } if (_forwardCompatibility) { return(XmlCaseOrder.None); } throw XsltException.Create(SR.Xslt_InvalidAttrValue, "case-order", value); }
public string GetNsAlias(ref string prefix) { Debug.Assert( Keywords.Equals(this.input.LocalName, this.input.Atoms.StylesheetPrefix) || Keywords.Equals(this.input.LocalName, this.input.Atoms.ResultPrefix) ); if (Keywords.Compare(this.input.Atoms.HashDefault, prefix)) { prefix = string.Empty; return(this.DefaultNamespace); } else { if (!PrefixQName.ValidatePrefix(prefix)) { throw XsltException.Create(Res.Xslt_InvalidAttrValue, this.input.LocalName, prefix); } return(this.ResolveXPathNamespace(prefix)); } }
private XmlSortOrder ParseOrder(string value) { if (value == null) { // Avt is not constant, or attribute wasn't defined return(XmlSortOrder.Ascending); } if (value == "ascending") { return(XmlSortOrder.Ascending); } if (value == "descending") { return(XmlSortOrder.Descending); } if (_forwardCompatibility) { return(XmlSortOrder.Ascending); } throw XsltException.Create(SR.Xslt_InvalidAttrValue, "order", value); }
private XmlSortOrder ParseOrder(string value) { if (value == null) // Avt is not constant, or attribute wasn't defined { return(XmlSortOrder.Ascending); } if (value == Keywords.s_Ascending) { return(XmlSortOrder.Ascending); } if (value == Keywords.s_Descending) { return(XmlSortOrder.Descending); } if (this.forwardCompatibility) { return(XmlSortOrder.Ascending); } throw XsltException.Create(Res.Xslt_InvalidAttrValue, Keywords.s_Order, value); }
public string GetNsAlias(ref string prefix) { Debug.Assert( Ref.Equal(_input.LocalName, _input.Atoms.StylesheetPrefix) || Ref.Equal(_input.LocalName, _input.Atoms.ResultPrefix) ); if (prefix == "#default") { prefix = string.Empty; return(this.DefaultNamespace); } else { if (!PrefixQName.ValidatePrefix(prefix)) { throw XsltException.Create(SR.Xslt_InvalidAttrValue, _input.LocalName, prefix); } return(this.ResolveXPathNamespace(prefix)); } }
private XmlCaseOrder ParseCaseOrder(string value) { if (value == null) // Avt is not constant, or attribute wasn't defined { return(XmlCaseOrder.None); } if (value == Keywords.s_UpperFirst) { return(XmlCaseOrder.UpperFirst); } if (value == Keywords.s_LowerFirst) { return(XmlCaseOrder.LowerFirst); } if (this.forwardCompatibility) { return(XmlCaseOrder.None); } throw XsltException.Create(Res.Xslt_InvalidAttrValue, Keywords.s_CaseOrder, value); }
private static PrefixQName CreateElementQName(string name, string nsUri, InputScopeManager manager) { if (nsUri == XmlReservedNs.NsXmlNs) { throw XsltException.Create(SR.Xslt_ReservedNS, nsUri); } PrefixQName qname = new PrefixQName(); qname.SetQName(name); if (nsUri == null) { qname.Namespace = manager.ResolveXmlNamespace(qname.Prefix); } else { qname.Namespace = nsUri; } return(qname); }
private string ParseLang(string value) { if (value == null) // Avt is not constant, or attribute wasn't defined { return(null); } // XmlComplianceUtil.IsValidLanguageID uses the outdated RFC 1766. It would be // better to remove this method completely and not call it here, but that may // change exception types for some stylesheets. if (!XmlComplianceUtil.IsValidLanguageID(value.ToCharArray(), 0, value.Length) && (value.Length == 0 || CultureInfo.GetCultureInfo(value) == null) ) { if (this.forwardCompatibility) { return(null); } throw XsltException.Create(Res.Xslt_InvalidAttrValue, "lang", value); } return(value); }
/* * CompileTopLevelElements */ protected void CompileDocument(Compiler compiler, bool inInclude) { NavigatorInput input = compiler.Input; // SkipToElement : while (input.NodeType != XPathNodeType.Element) { if (!compiler.Advance()) { throw XsltException.Create(SR.Xslt_WrongStylesheetElement); } } Debug.Assert(compiler.Input.NodeType == XPathNodeType.Element); if (Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl)) { if ( !Ref.Equal(input.LocalName, input.Atoms.Stylesheet) && !Ref.Equal(input.LocalName, input.Atoms.Transform) ) { throw XsltException.Create(SR.Xslt_WrongStylesheetElement); } compiler.PushNamespaceScope(); CompileStylesheetAttributes(compiler); CompileTopLevelElements(compiler); if (!inInclude) { CompileImports(compiler); } } else { // single template compiler.PushLiteralScope(); CompileSingleTemplate(compiler); } compiler.PopScope(); }
private String SystemProperty(string qname) { String result = string.Empty; string prefix; string local; PrefixQName.ParseQualifiedName(qname, out prefix, out local); // verify the prefix corresponds to the Xslt namespace string urn = LookupNamespace(prefix); if (urn == XmlReservedNs.NsXslt) { if (local == "version") { result = "1"; } else if (local == "vendor") { result = "Microsoft"; } else if (local == "vendor-url") { result = "http://www.microsoft.com"; } } else { if (urn == null && prefix != null) { // if prefix exist it has to be mapped to namespace. // Can it be "" here ? throw XsltException.Create(Res.Xslt_InvalidPrefix, prefix); } return(string.Empty); } return(result); }