Search code examples
xsltxslt-1.0ibm-datapoweribm-api-managementibm-api-connect

XSLT to remove soap envelope and soap namespaces and process the soap body


I need to remove the soap envelope and soap namespace from the input and pass it to the backend as xml For e.g: My input is

<xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soapenvelope" xmlns:tem="http://tempuri.org/">
 <soap:Body>
 <tem:Data xmlns="http://tempuri.org/">
 <tem:DATE>string</tem:DATE> 
 <tem:STATUS>string</tem:STATUS> 
 <tem:CODE>string</tem:CODE>
 </tem:Data>
 </soap:Body>
</soap:Envelope>

my expected output is:

<Data>
 <DATE>string</DATE> 
 <STATUS>string</STATUS> 
 <CODE>string</CODE>
 </Data>
 

iam using the below code:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output version="1.0" indent="yes" encoding="UTF-8" method="xml"/>

<xsl:template match="comment()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="/Body"/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

but iam getting the below output:

<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
 <Body>
 <Data>
 <DATE>string</IDATE> 
 <STATUS>string</STATUS> 
 <CODE>string</CODE>
 </Data>
 </Body>
</Envelope>

Solution

  • I think it would be sufficient to do:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    
    <xsl:template match="/*">
        <xsl:apply-templates select="*/*"/>
    </xsl:template>
    
    <xsl:template match="*">
        <xsl:element name="{local-name()}">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
    
    </xsl:stylesheet>