Re: Use of QName forcing declaration "Unused" namespaces
Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected]>
| Newsgroups | gmane.text.xml.saxon.help,gmane.text.xml.xsl.general.mulberrytech |
|---|---|
| Message-ID | <[email protected]> |
If the QNames are names of elements in the source document, then you shouldn't be calling name() to get the lexical QName, and then calling xs:QName to turn it back into an xs:QName value, because that loses information (specifically, the namespace bindings that were in scope in the source document). Instead, you should use the node-name() function to get the name as an xs:QName value in the first place. I may have misunderstood what's going on here, but I think this is the heart of the issue: if you're going to manipulate QNames, then you need to get them out of lexical format and into structured xs:QName format as early as possible, while the original namespace bindings are still known. Michael Kay Saxonica > On 21 Jul 2020, at 15:02, Ihe Onwuka <[email protected]> wrote: > > Every element in my input doc is in one of 5 namespaces that I have declared globally in the stylesheet. However the stylesheet as written never explicitly references any of the 5 namespaces so I would like to genericize it by doing away with the namespace declarations. > > However if I remove any one of the namespaces I get this error. > > Error at char 79 in expression in xsl:sequence/@select on line 14 column 118 of ***.xsl: > FONS0004 Namespace prefix {jx} has not been declared > at function local:localizedName on line 12 of ***.xsl: > > Here is the function local:localizedName which is designed to return a local name from a QName or a string. > > <xsl:function name="local:localizedName" as="xs:string?"> > <xsl:param name="name"/> > <xsl:sequence select="local-name-from-QName(if ($name instance of xs:QName) then $name else xs:QName($name))"/> > </xsl:function> > > It seems that casting anything as QName mandates that the namespace prefix in whatever is being cast must be declared , even if it's not explicitly referenced. > > e.g xs:string(xs:QName($someName)) will fail if $someName contains 'ab:cde' and you haven't declared the ab prefix anywhere (even if you don't otherwise use it). > > In which case my goal is better achieved by eradicating the QNames and resorting to string manipulation to extract the local part of the name. > > Comments, observations, corrections please. > _______________________________________________ > saxon-help mailing list archived at http://saxon.markmail.org/ > [email protected] > https://lists.sourceforge.net/lists/listinfo/saxon-help _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ [email protected] https://lists.sourceforge.net/lists/listinfo/saxon-help