• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1210
  • Last Modified:

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>
0
alandp
Asked:
alandp
  • 2
1 Solution
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now