I am facing an issue in renaming a xml tag using XSLT. Below is my input xml.
Original XML:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns:Response xmlns:ns="http://demo.test.classes.com">
<ns:return>
<ns:person>
<ns:personName></ns:personName>
<ns:personAge></ns:personAge>
<ns:personAddress>
<ns:addressType>official</ns:addressType>
<ns:addressLine1>official address line 1</ns:addressLine1>
</ns:personAddress>
<ns:personAddress>
<ns:addressType>residence</ns:addressType>
<ns:addressLine1>residence address line 1</ns:addressLine1>
</ns:personAddress>
</ns:person>
</ns:return>
</ns:Response>
</soapenv:Body>
</soapenv:Envelope>
Expected XML after transformation: This is the final xml which I am looking for!!!
<MyResponse>
<person>
<personName></personName>
<personAge></personAge>
<personAddress>
<addressType>official</addressType>
<addressLine1>official address line 1</addressLine1>
</personAddress>
<personAddress>
<addressType>residence</addressType>
<addressLine1>residence address line 1</addressLine1>
</personAddress>
</person>
</MyResponse>
This is the XSLT, I am using now. But this is not generating the xml which I need. The issue is, if I don't include the template match="ns:Response", the generated xml is similar to above xml except the root tag being "Response" and it perfectly matching my need. But when I introduce the match="ns:Response" the our xml is not formatted as xml, and the generated xml contain the namespace xmlns:ns="http://demo.test.classes.com" beside the "MyResponse" tag. please let me know what should be modified in the below xslt?
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<xsl:template xmlns:ns="http://demo.test.classes.com" match="ns:return">
<xsl:apply-templates/>
</xsl:template>
<xsl:template xmlns:ns="http://demo.test.classes.com" match="ns:Response">
<MyResponse><xsl:apply-templates select="node()|@*"/></MyResponse>
</xsl:template>
</xsl:stylesheet>