I am trying to rename a tag, using XSLT in WSO2 ESB template.
All my attempts get me the same error: Unable to create an OMElement using XSLT result.
One of the variants I have tried is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:param name="response_tag"/>
<xsl:template match="RESPONSE">
<xsl:element name="{$response_tag}" >
<xsl:for-each select="/RESPONSE/*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Another is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="request_tag"/>
<xsl:template match="RESPONSE">
<xsl:element name="{$request_tag}">
<xsl:apply-templates select="node() | @*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
What am I doing wrong?
PS. The parameter response_tag
value is similar to rns:NameOfResponse
The namespace (rns
) and NameOfResponse
could be different every time. The namespace is inside the Envelope tag of the xml, so in the end (if the transformation works), the xml would be valid.
The input will be something like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rns="http://www.example.com/example">
<soapenv:Header/>
<soapenv:Body>
<RESPONSE xmlns="http://ws.apache.org/ns/synapse">
<tag>123</tag>
<another_tag>20160622134457473</another_tag>
...
</RESPONSE>
</soapenv:Body>
</soapenv:Envelope>
The result should be:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rns="http://www.example.com/example">
<soapenv:Header/>
<soapenv:Body>
<rns:NameOfResponse>
<tag>123</tag>
<another_tag>20160622134457473</another_tag>
...
</rns:NameOfResponse>
</soapenv:Body>
</soapenv:Envelope>
PPS. Tried removing the namespace from the response tag - i.e. the response tag looks like: NameOfTag
now. Same error.