I am using WSO2 ESB 4.8.1 and I want to modify soap message using xslt.
My soap message:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getResponse xmlns:ns2="http://nis.ayss.com.tr/">
<return>
<result>true</result>
<responseList>
<name>STACK</name>
<number>001</number>
</responseList>
</return>
</ns2:getResponse>
</S:Body>
</S:Envelope>
I want to change "name" element to "brand" and modify this message like this:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getResponse xmlns:ns2="http://nis.ayss.com.tr/">
<return>
<result>true</result>
<responseList>
<brand>STACK</brand>
<number>001</number>
</responseList>
</return>
</ns2:getResponse>
</S:Body>
</S:Envelope>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns2="http://nis.ayss.com.tr/">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="name">
<brand>
<xsl:apply-templates select="@*|node()"/>
</brand>
</xsl:template>
</xsl:stylesheet>
I created an xslt file as a local entry in WSO2 ESB. But it adds a default namespace as xmlns="http://ws.apache.org/ns/synapse" and changes xslt as:
<xsl:template match="name">
<brand xmlns="http://ws.apache.org/ns/synapse">
<xsl:apply-templates select="@*|node()"/>
</brand>
</xsl:template>
So my result soap messsage is:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getResponse xmlns:ns2="http://nis.ayss.com.tr/">
<return>
<result>true</result>
<responseList>
<brand xmlns="http://ws.apache.org/ns/synapse">STACK</brand>
<number>001</number>
</responseList>
</return>
</ns2:getResponse>
</S:Body>
</S:Envelope>
How can I modify this element name without adding a namespace using XSLT in WSO2 ESB?
In your XSL local entry, replace the "brand" tag with a xsl:element
<xsl:template match="name">
<xsl:element name="brand">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>