cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT to remove namespace from specific element in SAP PI

Former Member
0 Kudos

Hi Experts,

I have one xml as below:

<?xml version="1.0" encoding="UTF-8"?>

  <ns0:TransferFile xmlns:ns0="http://tempuri.org/">

  <ns0:request>

  <ns1:ClientID xmlns:ns1="http://computershare.com/gds.externalServices/datacontracts">950</ns1:ClientID>

  <ns1:ContractID xmlns:ns1="http://computershare.com/gds.externalServices/datacontracts">95AAA</ns1:ContractID>

  <ns1:Data xmlns:ns1="http://computershare.com/gds.externalServices/datacontracts">Izw/eG1sIHZlcnNp</ns1:Data>

  <ns1:ExternalAuditId xmlns:ns1="http://computershare.com/gds.externalServices/datacontracts">SAPPI</ns1:ExternalAuditId>

  <ns1:Filename xmlns:ns1="http://computershare.com/gds.externalServices/datacontracts">E_CS_309_0123_20160830</ns1:Filename>

  <ns1:Password xmlns:ns1="http://computershare.com/gds.externalServices/datacontracts">12345/ns1:Password>

  <ns1:UserName xmlns:ns1="http://computershare.com/gds.externalServices/datacontracts">WebServiceTest</ns1:UserName>

  </ns0:request>

  </ns0:TransferFile>

I want to generate the below target xml:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">

    <soapenv:Body>

      <tem:TransferFile>

         <tem:request>

<dat:ClientID>950</dat:ClientID>

<dat:ContractID>950AAA</dat:ContractID>

<dat:Data><!-- Base 64 binary representation of data --></dat:Data>

<dat:ExternalAuditId><!--unique identifier --></dat:ExternalAuditId>

<dat:Filename><!-- Filename for embedded data --></dat:Filename>

<dat:Password><!-- Password --></dat:Password>

<dat:UserName><!-- Username --></dat:UserName>

         </tem:request>

      </tem:TransferFile>

   </soapenv:Body>

  </soapenv:Envelope>


However, I am unable to remove the namespace part from individual nodes like xmlns:dat="http://computershare.com/gds.externalServices/datacontracts" from ClientID and xmlns:tem="http://tempuri.org/" from TransferFile etc.


Also I am not able to add xmlns:tem="http://tempuri.org/" xmlns:dat="http://computershare.com/gds.externalServices/datacontracts" in the  <soapenv:Envelope> part.


I am using the below xsl right now:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://tempuri.org/" xmlns:ns1="http://computershare.com/gds.externalServices/datacontracts" xmlns:tem="http://tempuri.org/" xmlns:dat="http://computershare.com/gds.externalServices/datacontracts" exclude-result-prefixes="ns0 ns1">

    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

    <xsl:strip-space elements="*"/>

    <xsl:template match="/">

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">

            <soapenv:Body>

                <xsl:copy>

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

                </xsl:copy>

            </soapenv:Body>

        </soapenv:Envelope>

    </xsl:template>

    <xsl:template match="ns0:*">

        <xsl:element name="tem:{local-name()}">

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

        </xsl:element>

    </xsl:template>

    <xsl:template match="ns1:*">

        <xsl:element name="dat:{local-name()}">

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

        </xsl:element>

    </xsl:template>

</xsl:stylesheet>

But it generates the below output:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  
<soapenv:Body>
  
<tem:TransferFile xmlns:tem="http://tempuri.org/">
  
<tem:request>
  
<dat:ClientID xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">950</dat:ClientID>
  
<dat:ContractID xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">950AAA</dat:ContractID>
  
<dat:Data xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">Izw/eG1sIHZlcnNp</dat:Data>
  
<dat:DocumentClass xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">String</dat:DocumentClass>
  
<dat:ExternalAuditId xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">SAPPI</dat:ExternalAuditId>
  
<dat:Filename xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">E_CS_309_0123_20160830</dat:Filename>
  
<dat:Password xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">12345</dat:Password>
  
<dat:UserName xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">WebServiceTest</dat:UserName>
  
</tem:request>
  
</tem:TransferFile>
  
</soapenv:Body>
</soapenv:Envelope>


I am not able to remove the xmlns tag from between the nodes and add the other to xmlns tag in <soapenv:Envelope>.


Please assist.


Thanks & Regards,

Treya


Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Treya,

Try using this xsl


<?xml version="1.0" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:dat="http://computershare.com/gds.externalServices/datacontracts">

  <soapenv:Header/>

  <soapenv:Body>

      <tem:TransferFile>

  <tem:request>

  <dat:ClientID>

  <xsl:value-of select="normalize-space(//dat:ClientID)"/>

  </dat:ClientID>

  <dat:ContractID>

  <xsl:value-of select="normalize-space(//dat:ContractID)"/>

  </dat:ContractID>

  <dat:Data>

  <xsl:value-of select="normalize-space(//dat:Data)"/>

  </dat:Data>

  <dat:ExternalAuditId>

  <xsl:value-of select="normalize-space(//dat:ExternalAuditId)"/>

  </dat:ExternalAuditId>

  <dat:FileName>

  <xsl:value-of select="normalize-space(//dat:Filename)"/>

  </dat:FileName>

  <dat:Password>

  <xsl:value-of select="normalize-space(//dat:Password)"/>

  </dat:Password>

  <dat:UserName>

  <xsl:value-of select="normalize-space(//dat:UserName)"/>

  </dat:UserName>

  </tem:request>

      </tem:TransferFile>

  </soapenv:Body>

  </soapenv:Envelope>

  </xsl:template>

</xsl:stylesheet>

Test:

Regards,

Mark

Former Member
0 Kudos

Thanks a lot Mark,

This was really helpful, I got the output perfectly.

Regards,

Treya

Answers (0)