Link to home
Start Free TrialLog in
Avatar of alandp
alandp

asked on

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>
Avatar of MMeijer
MMeijer

<xsl:stylesheet
  exclude-result-prefixes = NCNames
</xsl:stylesheet>
Avatar of alandp

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of MMeijer
MMeijer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial