cancel
Showing results for 
Search instead for 
Did you mean: 

Need to remove first UsernameToken header on XML document using XSLT

Former Member
0 Kudos

Can someone help me with an XSLT transformation where i want to remove the first wsse:Security header from my request message. I am not an XSLT expert, so i started playing around with XSLT code but no luck yet.

My input message Before transformation

<soapenv:Envelope xmlns:acc="http://wsdl/AccountManagerDocLiteralWrapped/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <soapenv:Header>

   <wsse:Security soapenv:actor="actor1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

   <wsse:UsernameToken wsu:Id="UsernameToken-1436F53E829718B6F31400871123845250">

   <wsse:Username>user1</wsse:Username>

   <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>

   <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">TAOptcRrjG0vM85BrdbhPw==</wsse:Nonce>

   <wsu:Created>2014-05-23T18:52:03.845Z</wsu:Created>

   </wsse:UsernameToken>

   </wsse:Security>

   <wsse:Security soapenv:actor="actor2" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

   <wsse:UsernameToken wsu:Id="UsernameToken-1436F53E829718B6F31400871123845250">

   <wsse:Username>user2</wsse:Username>

   <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>

   <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">TAOptcRrjG0vM85BrdbhPw==</wsse:Nonce>

   <wsu:Created>2014-05-23T18:52:03.845Z</wsu:Created>

   </wsse:UsernameToken>

   </wsse:Security>

   </soapenv:Header>

   <soapenv:Body>

      <acc:transfer>

         <acc:acctFrom>AC1</acc:acctFrom>

         <acc:acctTo>AC2</acc:acctTo>

         <acc:amount>9</acc:amount>

      </acc:transfer>

   </soapenv:Body>

</soapenv:Envelope>

Expected Output after Transformation

<soapenv:Envelope xmlns:acc="http://wsdl/AccountManagerDocLiteralWrapped/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <soapenv:Header>

   <wsse:Security soapenv:actor="actor2" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

   <wsse:UsernameToken wsu:Id="UsernameToken-1436F53E829718B6F31400871123845250">

   <wsse:Username>user2</wsse:Username>

   <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>

   <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">TAOptcRrjG0vM85BrdbhPw==</wsse:Nonce>

   <wsu:Created>2014-05-23T18:52:03.845Z</wsu:Created>

   </wsse:UsernameToken>

   </wsse:Security>

   </soapenv:Header>

   <soapenv:Body>

      <acc:transfer>

         <acc:acctFrom>AC1</acc:acctFrom>

         <acc:acctTo>AC2</acc:acctTo>

         <acc:amount>9</acc:amount>

      </acc:transfer>

   </soapenv:Body>

</soapenv:Envelope>

Appreciate any help with this.

- dk

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Deepthi,

Please give the following snippet a try, it should ignore the first occurence of wsse:Security for the output (the first template is used to copy everything into the output, the second template is overruling the first template for the first occurence of wsse:Security and creates an empty output for it):

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">

<xsl:output omit-xml-declaration="yes"/>

    <xsl:template match="node()|@*">

      <xsl:copy>

         <xsl:apply-templates select="node()|@*"/>

      </xsl:copy>

    </xsl:template>

    <xsl:template match="wsse:Security[1]"/>

</xsl:stylesheet>