[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

[XSLT 1.0] Strip unused namespaces, but retain namespa

Subject: [XSLT 1.0] Strip unused namespaces, but retain namespace declarations for elements with QName values?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Wed, 30 Mar 2011 13:50:32 -0400
 [XSLT 1.0] Strip unused namespaces
Hi Folks,

I want to transform this:

--------------------------------------------
<t:Test xmlns:t="http://www.test.org"
        xmlns:unused="http://www.unused.org"
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

    <t:faultcode>SOAP:client</t:faultcode>

</t:Test>
--------------------------------------------

to this:

------------------------------------
<Test xmlns="http://www.test.org"
      xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

  <faultcode>SOAP:client</faultcode>

</Test>
------------------------------------

That is, I want to:

1. Replace namespace-qualified elements with a default namespace, e.g.,

   Change this: <t:Test xmlns:t="..."

   to this: <Test xmlns="..."


2. Delete unused namespace declarations, e.g.,

   Delete this: xmlns:unused="..."


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>


The following template rule does (1) and (2) but fails to implement (3):

    <xsl:template match="*[namespace-uri()]">

        <xsl:element name="{local-name()}"
                     namespace="{namespace-uri()}">
            <xsl:apply-templates select="@* | node()"/>
        </xsl:element>

    </xsl:template>

Any ideas? I am using XSLT 1.0

/Roger

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.