Re: [xsl] [XSLT 1.0] Strip unused namespaces, but retain namespace declarations for elements with QName values?

Subject: Re: [xsl] [XSLT 1.0] Strip unused namespaces, but retain namespace declarations for elements with QName values?
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 30 Mar 2011 19:53:31 +0100
3. Retain a namespace declaration if it declares a namespace prefix that is used in an element QName value, e.g.,

Retain this: xmlns:soap="..."

because the prefix is used in this element's value:<faultcode>SOAP:client</faultcode>


Well, the prefix isn't used in the value. SOAP and soap are quite different prefixes.

If prefixes are used only as part of element values that are QNames, you might be able to do this. If prefixes can also appear, as they do in XSLT, in contexts like exclude-result-prefixes="a b c d" then you are out of luck, unless you have knowledge of the semantics of the vocabulary.

You could for example find all the namespace prefixes that are in use in QNames in content as

//*[contains(., ':) and . castable as xs:QName]/substring-before(., ':')

and then ensure that namespace declarations for this prefix are copied.

Michael Kay
Saxonica

Current Thread