How can I remove a specific namespace in an XSL transform?

Hi,

Getting stuck on an XSL transform I am writing and wonder if anyone can help...

I have included all the stages of the transform below.

The idea is that input doc is transformed so the wsse:Security section is completely removed and custom header tags exist in its place.

As you can see in the output doc below, it almost completely removes all traces of the wsse tags but leaves in the xmlns:wsse namespace declaration in the soapenv:Envelope tag. How can I also remove this in the transformation? Do I need to setup the identity transform in such a way as to not copy this (if so how can I do this?) Or... is there a better way?

One of the many things I tried was using exclude-result-prefixes but for some reason that has no effect.

Many thanks,
Alan

Input doc:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <soapenv:Header>
            <wsse:Security>
                  <wsse:UsernameToken>
                        <wsse:Username>username</wsse:Username>
                        <wsse:Password>password</wsse:Password>
                  </wsse:UsernameToken>
            </wsse:Security>
      </soapenv:Header>
      <soapenv:Body>
            <Request>
                  <SomeData>Somedata</SomeData>
            </Request>
      </soapenv:Body>
</soapenv:Envelope>
 
XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:test="http://www.test.com/test_1" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <xsl:output method="xml" indent="yes"/>
      
      <!-- Replace Security header with Context elements -->
      <xsl:template match="/*[local-name()='Envelope']/*[local-name()='Header']/*[local-name()='Security']">
            <!-- Construct the context data in the message -->
            <test:a>
                  <xsl:value-of select="'a'"/>
            </test:a>
            <test:b>
                  <xsl:value-of select="'b'"/>
            </test:b>
            <test:c>
                  <xsl:value-of select="'c'"/>
            </test:c>
      </xsl:template>
      
      <!-- Identity transform  -->
      <xsl:template match="@*|node()">
            <xsl:copy>
                  <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
      </xsl:template>
</xsl:stylesheet>
 
Output doc:
(the xmlns:wsse namespace declaration should NOT exist in the message below).

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <soapenv:Header>
            <test:a xmlns:test="http://www.test.com/test_1">a</test:a>
            <test:b xmlns:test="http://www.test.com/test_1">b</test:b>
            <test:c xmlns:test="http://www.test.com/test_1">c</test:c>
      </soapenv:Header>
      <soapenv:Body>
            <Request>
                  <SomeData>Somedata</SomeData>
            </Request>
      </soapenv:Body>
</soapenv:Envelope>
alandpAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MMeijerCommented:
<xsl:stylesheet
  exclude-result-prefixes = NCNames
</xsl:stylesheet>
0
alandpAuthor Commented:
Thanks for your response, I had tried

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:test="http://www.test.com/test_1" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" exclude-result-prefixes = "wsse">

but it still remained.

Alan
0
MMeijerCommented:
the xsl:copy forces it to be added (didn't knew that :) ) as i replaced the copy template with this, it was gone


      <!-- Identity transform  -->

      <xsl:template match="*">
            <xsl:element name="{name()}">
                  <xsl:for-each select="@*">
                        <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
                  </xsl:for-each>
                  <xsl:apply-templates select="*" />
            </xsl:element>
      </xsl:template>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.