Subject: [xsl] Re: [saxon] Use of QName forcing declaration "Unused" namespaces From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 21 Jul 2020 23:48:50 -0000 |
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 <ihe.onwuka@xxxxxxxxx> 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/ > saxon-help@xxxxxxxxxxxxxxxxxxxxx > https://lists.sourceforge.net/lists/listinfo/saxon-help
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: [saxon] Use of QName forc, Norman Tovey-Walsh n | Thread | [xsl] Re: [saxon] Use of QName forc, Michael Kay mike@xxx |
[xsl] Re: [saxon] Use of QName forc, Norman Tovey-Walsh n | Date | [xsl] Re: [saxon] Use of QName forc, Michael Kay mike@xxx |
Month |