How to rename a tag using XSLT
<p>I am trying to rename a tag, using XSLT in WSO2 ESB template.</p>

<p>All my attempts get me the same error: <em>Unable to create an OMElement using XSLT result.</em></p>

<p>One of the variants I have tried is:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="/"&gt;
        &lt;xsl:apply-templates /&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:param name="response_tag"/&gt;
    &lt;xsl:template match="RESPONSE"&gt;
        &lt;xsl:element name="{$response_tag}" &gt;
            &lt;xsl:for-each select="/RESPONSE/*"&gt;
                &lt;xsl:copy&gt;
                    &lt;xsl:apply-templates select="@*|node()"/&gt;
                &lt;/xsl:copy&gt;
            &lt;/xsl:for-each&gt;
        &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>

<p>Another is:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/&gt;

    &lt;xsl:param name="request_tag"/&gt;
    &lt;xsl:template match="RESPONSE"&gt;
        &lt;xsl:element name="{$request_tag}"&gt;
            &lt;xsl:apply-templates select="node() | @*" /&gt;
        &lt;/xsl:element&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</code></pre>

<p>What am I doing wrong? </p>

<p>PS. The parameter <code>response_tag</code> value is similar to <code>rns:NameOfResponse</code>
The namespace (<code>rns</code>) and <code>NameOfResponse</code> 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.</p>

<p>The input will be something like: </p>

<pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rns="http://www.example.com/example"&gt;
   &lt;soapenv:Header/&gt;
   &lt;soapenv:Body&gt;
      &lt;RESPONSE xmlns="http://ws.apache.org/ns/synapse"&gt;
         &lt;tag&gt;123&lt;/tag&gt;
         &lt;another_tag&gt;20160622134457473&lt;/another_tag&gt;
        ...
     &lt;/RESPONSE&gt;
   &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;
</code></pre>

<p>The result should be:</p>

<pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rns="http://www.example.com/example"&gt;
   &lt;soapenv:Header/&gt;
   &lt;soapenv:Body&gt;
      &lt;rns:NameOfResponse&gt;
         &lt;tag&gt;123&lt;/tag&gt;
         &lt;another_tag&gt;20160622134457473&lt;/another_tag&gt;
        ...
     &lt;/rns:NameOfResponse&gt;
   &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;
</code></pre>

<p>PPS. Tried removing the namespace from the response tag - i.e. the response tag looks like: <code>NameOfTag</code> now. Same error. </p>