0

im using datapower SOA

i have an XML :

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<data>data</data>
</s:Body>
</s:Envelope>

i want to change it to :

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ns0:ReceptionRequest xmlns:ns0="ReceptionRequest">
<Message>
<data>data</data>
</Message>
</ns0:ReceptionRequest>
</s:Body>
</s:Envelope>

please assist me with XSL

how do i add something before and after the tag

alex
  • 916
  • 4
  • 12
  • 26

2 Answers2

0

You can use the following XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="ReceptionRequest" exclude-result-prefixes="soap">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

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

    <xsl:template match="soap:Body">
        <xsl:copy>
            <ns0:ReceptionRequest xmlns:ns0="ReceptionRequest">
                <Message>
                    <xsl:apply-templates />
                </Message>
            </ns0:ReceptionRequest>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

The <xsl:template match="soap:Body"> will make the new elements and copy the <data> element

Mark Veenstra
  • 4,691
  • 6
  • 35
  • 66
0

You can use below code also which will copy and its value.

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

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

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

</xsl:template>

    <xsl:template match = "*[local-name() = 'Body']">

      <xsl:copy>
      <ns0:ReceptionRequest xmlns:ns0="ReceptionRequest">
        <Message>
           <xsl:copy-of  select ="*[local-name() = 'data']"/>

        </Message>
    </ns0:ReceptionRequest>
     </xsl:copy>
   </xsl:template>


</xsl:stylesheet>
sreevathsa a
  • 149
  • 13