Re: How to output the unused namespaces in the XML do
<xsl:for-each select="//namespace::*[not(. = (preceding::*|../ancestor::*)/namespace::*)]">
<xsl:if test="not((//* | //@*)[namespace-uri(.) = current()])">
This namespace is unused: <xsl:value-of select="."/>
Things are much easier in XSLT/XPath 2.0 (assuming current() bound to document node):
distinct-values(//namespace::*)[not(. = (current()//*|current()//@*)/namespace-uri(.))]
Neither of our solutions checks for unused prefixes, e.g., if the document had multiple declarations for the same URI but uses only one of the prefixes on element/attribute names. That could be done in XSLT 2.0, but whether or not it would work in XSLT 1.0 is dependent on how your processor implements name(). (XPath 2.0 provides direct access to what prefix was used, but XPath 1.0 does not.)
Keep in mind that the above tests don't guarantee that the namespace isn't "used." If your input document is XSLT, XSD, or any other vocabulary that uses QNames in content, you can't safely assume the namespace isn't being used.
-- Evan Lenz Lenz Consulting Group, Inc. http://lenzconsulting.com +1 (360) 297-0087
Costello, Roger L. wrote:
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format