private PrefixQName qname; // When we not have AVTs at all we can do this. null otherwise. private static PrefixQName CreateAttributeQName(string name, string nsUri, InputScopeManager manager) { // if name == "xmlns" we don't need to generate this attribute. // to avoid i'ts generation we can return false and not add AtributeCation to it's parent container action // for now not creating this.qname will do the trick at execution time if (name == Keywords.s_Xmlns) return null; if (nsUri == Keywords.s_XmlnsNamespace) { throw new XsltException(Res.Xslt_ReservedNS, nsUri); } PrefixQName qname = new PrefixQName(); qname.SetQName(name); qname.Namespace = nsUri != null ? nsUri : manager.ResolveXPathNamespace(qname.Prefix); if(qname.Prefix.StartsWith("xml")) { if( qname.Prefix.Length == 3 && qname.Namespace == Keywords.s_XmlNamespace && (qname.Name == "lang" || qname.Name == "space") ) { // preserve prefix for xml:lang and xml:space } else if (qname.Prefix == Keywords.s_Xmlns && nsUri == null) { // if NS wasn't specified we have to use prefix to find it and this is imposible for 'xmlns' throw new XsltException(Res.Xslt_InvalidPrefix, qname.Prefix); } else { qname.ClearPrefix(); } } return qname; }
public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext) { XsltCompileContext xsltCompileContext = (XsltCompileContext)xsltContext; ArrayList ResultList = new ArrayList(); string local, prefix; PrefixQName.ParseQualifiedName(ToString(args[0]), out prefix, out local); string ns = xsltContext.LookupNamespace(prefix); XmlQualifiedName qname = new XmlQualifiedName(local, ns); XPathNodeIterator it = args[1] as XPathNodeIterator; if (it != null) { while (it.MoveNext()) { xsltCompileContext.FindKeyMatch(qname, it.Current.Value, ResultList, docContext); } } else { xsltCompileContext.FindKeyMatch(qname, ToString(args[1]), ResultList, docContext); } return(new XPathArrayIterator(ResultList)); }
internal override void Compile(Compiler compiler) { CompileAttributes(compiler); CheckRequiredAttribute(compiler, this.nameAvt, Keywords.s_Name); this.name = PrecalculateAvt(ref this.nameAvt); this.nsUri = PrecalculateAvt(ref this.nsAvt); // if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore if (this.nameAvt == null && this.nsAvt == null) { if (this.name != Keywords.s_Xmlns) { this.qname = CreateAttributeQName(this.name, this.nsUri, compiler.CloneScopeManager()); } } else { this.manager = compiler.CloneScopeManager(); } if (compiler.Recurse()) { CompileTemplate(compiler); compiler.ToParent(); } }
// see http://www.w3.org/TR/xslt#function-element-available private bool ElementAvailable(string qname) { string name, prefix; PrefixQName.ParseQualifiedName(qname, out prefix, out name); string ns = this.manager.ResolveXmlNamespace(prefix); // msxsl:script - is not an "instruction" so we return false for it. if (ns == Keywords.s_XsltNamespace) { return( name == Keywords.s_ApplyImports || name == Keywords.s_ApplyTemplates || name == Keywords.s_Attribute || name == Keywords.s_CallTemplate || name == Keywords.s_Choose || name == Keywords.s_Comment || name == Keywords.s_Copy || name == Keywords.s_CopyOf || name == Keywords.s_Element || name == Keywords.s_Fallback || name == Keywords.s_ForEach || name == Keywords.s_If || name == Keywords.s_Message || name == Keywords.s_Number || name == Keywords.s_ProcessingInstruction || name == Keywords.s_Text || name == Keywords.s_ValueOf || name == Keywords.s_Variable ); } return(false); }
internal XmlQualifiedName CreateXmlQName(string qname) { string prefix, local; PrefixQName.ParseQualifiedName(qname, out prefix, out local); return(new XmlQualifiedName(local, this.scopeManager.ResolveXmlNamespace(prefix))); }
internal override void Execute(Processor processor, ActionFrame frame) { Debug.Assert(processor != null && frame != null); switch (frame.State) { case Initialized: if (this.qname != null) { frame.CalulatedName = this.qname; } else { frame.CalulatedName = CreateElementQName( this.nameAvt == null ? this.name : this.nameAvt.Evaluate(processor, frame), this.nsAvt == null ? this.nsUri : this.nsAvt.Evaluate(processor, frame), this.manager ); } goto case NameDone; case NameDone: { PrefixQName qname = frame.CalulatedName; if (processor.BeginEvent(XPathNodeType.Element, qname.Prefix, qname.Name, qname.Namespace, this.empty) == false) { // Come back later frame.State = NameDone; break; } if (!this.empty) { processor.PushActionFrame(frame); frame.State = ProcessingChildren; break; // Allow children to run } else { goto case ProcessingChildren; } } case ProcessingChildren: if (processor.EndEvent(XPathNodeType.Element) == false) { Debug.WriteLine("Cannot end event, breaking, will restart"); frame.State = ProcessingChildren; break; } frame.Finished(); break; default: Debug.Fail("Invalid ElementAction execution state"); break; } }
public static bool ValidatePrefix(string prefix) { int position = 0; try { PrefixQName.ParseNCName(prefix, ref position); } catch (Exception) {} return(position == prefix.Length); }
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.ToLower(CultureInfo.InvariantCulture); // Case insensetive ! if (langName == "jscript" || langName == "javascript") { lang = ScriptingLanguage.JScript; } else if (langName == "vb" || langName == "visualbasic") { lang = ScriptingLanguage.VisualBasic; } else if (langName == "c#" || langName == "csharp") { lang = ScriptingLanguage.CSharp; } else { throw new XsltException(Res.Xslt_ScriptInvalidLang, langName); } } else if (input.LocalName == input.Atoms.ImplementsPrefix) { if (!PrefixQName.ValidatePrefix(input.Value)) { throw XsltException.InvalidAttrValue(input.LocalName, input.Value); } implementsNamespace = compiler.ResolveXmlNamespace(input.Value); } }while (input.MoveToNextAttribute()); input.ToParent(); } if (implementsNamespace == null) { throw new XsltException(Res.Xslt_MissingAttribute, input.Atoms.ImplementsPrefix); } if (!input.Recurse() || input.NodeType != XPathNodeType.Text) { throw new XsltException(Res.Xslt_ScriptEmpty); } compiler.AddScript(input.Value, lang, implementsNamespace, input.BaseURI, input.LineNumber); input.ToParent(); }
// see: http://www.w3.org/TR/xslt#function-function-available private bool FunctionAvailable(string qname) { string name, prefix; PrefixQName.ParseQualifiedName(qname, out prefix, out name); string ns = LookupNamespace(prefix); if (ns == Keywords.s_MsXsltNamespace) { return(name == f_NodeSet); } else if (ns == string.Empty) { return( // It'll be better to get this information from XPath name == "last" || name == "position" || name == "name" || name == "namespace-uri" || name == "local-name" || name == "count" || name == "id" || name == "string" || name == "concat" || name == "starts-with" || name == "contains" || name == "substring-before" || name == "substring-after" || name == "substring" || name == "string-length" || name == "normalize-space" || name == "translate" || name == "boolean" || name == "not" || name == "true" || name == "false" || name == "lang" || name == "number" || name == "sum" || name == "floor" || name == "ceiling" || name == "round" || // XSLT functions: (s_FunctionTable[name] != null && name != "unparsed-entity-uri") ); } else { // Is this script or extention function? object extension; return(GetExtentionMethod(ns, name, /*argTypes*/ null, out extension) != null); } }
private PrefixQName qname; // When we not have AVTs at all we can do this. null otherwise. private static PrefixQName CreateAttributeQName(string name, string nsUri, InputScopeManager manager) { // if name == "xmlns" we don't need to generate this attribute. // to avoid i'ts generation we can return false and not add AtributeCation to it's parent container action // for now not creating this.qname will do the trick at execution time if (name == Keywords.s_Xmlns) { return(null); } if (nsUri == Keywords.s_XmlnsNamespace) { throw new XsltException(Res.Xslt_ReservedNS, nsUri); } PrefixQName qname = new PrefixQName(); qname.SetQName(name); qname.Namespace = nsUri != null ? nsUri : manager.ResolveXPathNamespace(qname.Prefix); if (qname.Prefix.StartsWith("xml")) { if (qname.Prefix.Length == 3) // prefix == "xml" { if (qname.Namespace == Keywords.s_XmlNamespace && (qname.Name == "lang" || qname.Name == "space")) { // preserve prefix for xml:lang and xml:space } else { qname.ClearPrefix(); } } else if (qname.Prefix == Keywords.s_Xmlns) { if (qname.Namespace == Keywords.s_XmlnsNamespace) { // if NS wasn't specified we have to use prefix to find it and this is imposible for 'xmlns' throw new XsltException(Res.Xslt_InvalidPrefix, qname.Prefix); } else { qname.ClearPrefix(); } } } return(qname); }
private static PrefixQName CreateElementQName(string name, string nsUri, InputScopeManager manager) { if (nsUri == Keywords.s_XmlnsNamespace) { throw new XsltException(Res.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 FormatNumber(double value, string formatPattern, String formatName) { string ns = string.Empty, local = string.Empty; if (formatName != null) { string prefix; PrefixQName.ParseQualifiedName(formatName, out prefix, out local); ns = LookupNamespace(prefix); } DecimalFormat formatInfo = this.processor.RootAction.GetDecimalFormat(new XmlQualifiedName(local, ns)); if (formatInfo == null) { if (formatName != null) { throw new XsltException(Res.Xslt_NoDecimalFormat, formatName); } formatInfo = new DecimalFormat(new NumberFormatInfo(), '#', '0', ';'); } int[] groupsize = { ValidateFormat(ref formatPattern, formatInfo, value < 0) }; NumberFormatInfo numberInfo = formatInfo.info; numberInfo.NumberGroupSizes = groupsize; String result = value.ToString(formatPattern, numberInfo); if (formatInfo.zeroDigit != '0') { StringBuilder builder = new StringBuilder(result.Length); int startingLetter = Convert.ToInt32(formatInfo.zeroDigit) - Convert.ToInt32('0');; for (int i = 0; i < result.Length; i++) { if (result[i] >= '0' && result[i] <= '9') { builder.Append((char)(Convert.ToInt32(result[i]) + startingLetter)); } else { builder.Append(result[i]); } } result = builder.ToString(); } return(result); }
void NameTest(String name, Compiler compiler) { if (name == "*") { return; } if (name.EndsWith(":*")) { if (!PrefixQName.ValidatePrefix(name.Substring(0, name.Length - 3))) { throw XsltException.InvalidAttrValue(compiler.Input.LocalName, name); } } else { string prefix, localname; PrefixQName.ParseQualifiedName(name, out prefix, out localname); } }
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) || prefix.Length == 0) { throw XsltException.InvalidAttrValue(this.input.LocalName, prefix); } return(this.ResolveXPathNamespace(prefix)); } }
private static PrefixQName CreateElementQName(string name, string nsUri, InputScopeManager manager) { if (nsUri == Keywords.s_XmlnsNamespace) { throw new XsltException(Res.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 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 == Keywords.s_XsltNamespace) { 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 new XsltException(Res.Xslt_InvalidPrefix, prefix); } return(String.Empty); } return(result); }
internal override void Compile(Compiler compiler) { CompileAttributes(compiler); CheckRequiredAttribute(compiler, this.nameAvt, Keywords.s_Name); this.name = PrecalculateAvt(ref this.nameAvt); this.nsUri = PrecalculateAvt(ref this.nsAvt ); // if both name and ns are not AVT we can calculate qname at compile time and will not need namespace manager anymore if (this.nameAvt == null && this.nsAvt == null) { if(this.name != Keywords.s_Xmlns) { this.qname = CreateAttributeQName(this.name, this.nsUri, compiler.CloneScopeManager()); } } else { this.manager = compiler.CloneScopeManager(); } if (compiler.Recurse()) { CompileTemplate(compiler); compiler.ToParent(); } }
private XmlDataType ParseDataType(string value, InputScopeManager manager) { if (value == null) // Avt is not constant, or attribute wasn't defined { return(XmlDataType.Text); } if (value == Keywords.s_Text) { return(XmlDataType.Text); } if (value == Keywords.s_Number) { return(XmlDataType.Number); } String prefix, localname; PrefixQName.ParseQualifiedName(value, out prefix, out localname); manager.ResolveXmlNamespace(prefix); if (prefix == String.Empty && !this.forwardCompatibility) { throw XsltException.InvalidAttrValue(Keywords.s_DataType, value); } return(XmlDataType.Text); }
internal void SetQName(string qname) { PrefixQName.ParseQualifiedName(qname, out Prefix, out Name); }