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
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
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.