public void CompileAttributes(Compiler compiler) { NavigatorInput input = compiler.Input; string element = input.LocalName; if (input.MoveToFirstAttribute()) { do { if (input.NamespaceURI.Length != 0) { continue; } try { if (CompileAttribute(compiler) == false) { throw XsltException.Create(Res.Xslt_InvalidAttribute, input.LocalName, element); } }catch { 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(); } }
private void AddScript(Compiler compiler) { NavigatorInput input = compiler.Input; ScriptingLanguage lang = ScriptingLanguage.JScript; string implementsNamespace = null; if (input.MoveToFirstAttribute()) { do { if (input.LocalName == input.Atoms.Language) { string langName = input.Value; if ( String.Compare(langName, "jscript", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(langName, "javascript", StringComparison.OrdinalIgnoreCase) == 0 ) { lang = ScriptingLanguage.JScript; } else if ( String.Compare(langName, "c#", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(langName, "csharp", StringComparison.OrdinalIgnoreCase) == 0 ) { lang = ScriptingLanguage.CSharp; } else { throw XsltException.Create(Res.Xslt_ScriptInvalidLanguage, langName); } } else if (input.LocalName == input.Atoms.ImplementsPrefix) { if (!PrefixQName.ValidatePrefix(input.Value)) { throw XsltException.Create(Res.Xslt_InvalidAttrValue, input.LocalName, input.Value); } implementsNamespace = compiler.ResolveXmlNamespace(input.Value); } }while (input.MoveToNextAttribute()); input.ToParent(); } if (implementsNamespace == null) { throw XsltException.Create(Res.Xslt_MissingAttribute, input.Atoms.ImplementsPrefix); } if (!input.Recurse() || input.NodeType != XPathNodeType.Text) { throw XsltException.Create(Res.Xslt_ScriptEmpty); } compiler.AddScript(input.Value, lang, implementsNamespace, input.BaseURI, input.LineNumber); input.ToParent(); }
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(SR.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); }
private void CompileLiteralAttributesAndNamespaces(Compiler compiler) { NavigatorInput input = compiler.Input; if (input.Navigator.MoveToAttribute("use-attribute-sets", input.Atoms.UriXsl)) { AddAction(compiler.CreateUseAttributeSetsAction()); input.Navigator.MoveToParent(); } compiler.InsertExcludedNamespace(); if (input.MoveToFirstNamespace()) { do { string uri = input.Value; if (uri == XmlReservedNs.NsXslt) { continue; } if ( compiler.IsExcludedNamespace(uri) || compiler.IsExtensionNamespace(uri) || compiler.IsNamespaceAlias(uri) ) { continue; } this.AddEvent(new NamespaceEvent(input)); }while (input.MoveToNextNamespace()); input.ToParent(); } if (input.MoveToFirstAttribute()) { do { // Skip everything from Xslt namespace if (Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl)) { continue; } // Add attribute events this.AddEvent(compiler.CreateBeginEvent()); this.AddEvents(compiler.CompileAvt(input.Value)); this.AddEvent(new EndEvent(XPathNodeType.Attribute)); }while (input.MoveToNextAttribute()); input.ToParent(); } }
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 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 string GetSingleAttribute(string attributeAtom) { NavigatorInput input = Input; string element = input.LocalName; string value = null; if (input.MoveToFirstAttribute()) { do { string nspace = input.NamespaceURI; string name = input.LocalName; if (nspace.Length != 0) { continue; } if (Ref.Equal(name, attributeAtom)) { value = input.Value; } else { if (!this.ForwardCompatibility) { throw XsltException.Create(SR.Xslt_InvalidAttribute, name, element); } } }while (input.MoveToNextAttribute()); input.ToParent(); } if (value == null) { throw XsltException.Create(SR.Xslt_MissingAttribute, attributeAtom); } return(value); }
internal void CompileSingleTemplate(Compiler compiler) { NavigatorInput input = compiler.Input; // // find mandatory version attribute and launch compilation of single template // string?version = null; if (input.MoveToFirstAttribute()) { do { string nspace = input.NamespaceURI; string name = input.LocalName; if (Ref.Equal(nspace, input.Atoms.UriXsl) && Ref.Equal(name, input.Atoms.Version)) { version = input.Value; } }while (input.MoveToNextAttribute()); input.ToParent(); } if (version == null) { if (Ref.Equal(input.LocalName, input.Atoms.Stylesheet) && input.NamespaceURI == XmlReservedNs.NsWdXsl) { throw XsltException.Create(SR.Xslt_WdXslNamespace); } throw XsltException.Create(SR.Xslt_WrongStylesheetElement); } compiler.AddTemplate(compiler.CreateSingleTemplateAction()); }
internal void CompileStylesheetAttributes(Compiler compiler) { NavigatorInput input = compiler.Input; string element = input.LocalName; string? badAttribute = null; string? version = null; if (input.MoveToFirstAttribute()) { do { string nspace = input.NamespaceURI; string name = input.LocalName; if (nspace.Length != 0) { continue; } if (Ref.Equal(name, input.Atoms.Version)) { version = input.Value; if (1 <= XmlConvert.ToXPathDouble(version)) { compiler.ForwardCompatibility = (version != "1.0"); } else { // XmlConvert.ToXPathDouble(version) an be NaN! if (!compiler.ForwardCompatibility) { throw XsltException.Create(SR.Xslt_InvalidAttrValue, "version", version); } } } else if (Ref.Equal(name, input.Atoms.ExtensionElementPrefixes)) { compiler.InsertExtensionNamespace(input.Value); } else if (Ref.Equal(name, input.Atoms.ExcludeResultPrefixes)) { compiler.InsertExcludedNamespace(input.Value); } else if (Ref.Equal(name, input.Atoms.Id)) { // Do nothing here. } else { // We can have version attribute later. For now remember this attribute and continue badAttribute = name; } }while (input.MoveToNextAttribute()); input.ToParent(); } if (version == null) { throw XsltException.Create(SR.Xslt_MissingAttribute, "version"); } if (badAttribute != null && !compiler.ForwardCompatibility) { throw XsltException.Create(SR.Xslt_InvalidAttribute, badAttribute, element); } }
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 { if (input.Prefix.Length != 0) { continue; } string name = input.LocalName; string value = input.Value; if (Ref.Equal(name, input.Atoms.Name)) { Name = compiler.CreateXPathQName(value); } else if (Ref.Equal(name, input.Atoms.DecimalSeparator)) { info.NumberDecimalSeparator = value; } else if (Ref.Equal(name, input.Atoms.GroupingSeparator)) { info.NumberGroupSeparator = value; } else if (Ref.Equal(name, input.Atoms.Infinity)) { info.PositiveInfinitySymbol = value; } else if (Ref.Equal(name, input.Atoms.MinusSign)) { info.NegativeSign = value; } else if (Ref.Equal(name, input.Atoms.NaN)) { info.NaNSymbol = value; } else if (Ref.Equal(name, input.Atoms.Percent)) { info.PercentSymbol = value; } else if (Ref.Equal(name, input.Atoms.PerMille)) { info.PerMilleSymbol = value; } else if (Ref.Equal(name, input.Atoms.Digit)) { if (CheckAttribute(value.Length == 1, compiler)) { format.digit = value[0]; } } else if (Ref.Equal(name, input.Atoms.ZeroDigit)) { if (CheckAttribute(value.Length == 1, compiler)) { format.zeroDigit = value[0]; } } else if (Ref.Equal(name, input.Atoms.PatternSeparator)) { if (CheckAttribute(value.Length == 1, compiler)) { format.patternSeparator = value[0]; } } }while (input.MoveToNextAttribute()); input.ToParent(); } info.NegativeInfinitySymbol = string.Concat(info.NegativeSign, info.PositiveInfinitySymbol); if (Name == null) { Name = new XmlQualifiedName(); } compiler.AddDecimalFormat(Name, format); CheckEmpty(compiler); }