I'm trying to transform an input XML to a new XML format altogether.It isn't preserving the namespaces on the Output XML. I have tried few suggestions from SO, but since I am creating new root elements it is not preserving the namespaces. Any help is much appreciated! Thanks in Advance!
The input XML is :
<Container
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://hgkl.kj.com">
<Request>
<Id>Guid</Id>
<Name>ABC</Name>
</Request>
</Container>
The XSLT :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="/*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*">
<xsl:variable name="root" select="name()" />
<xsl:element name="{$root}">
<xsl:apply-templates select="child::*"/>
</xsl:element>
</xsl:template>
<xsl:template match="child::*">
<xsl:element name="Input">
// rest of the logic
</xsl:element>
</xsl:template>
</xsl:stylesheet>
The expected output :
<?xml version="1.0" encoding="UTF-8"?>
<Container>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://hgkl.kj.com">
<Input>
// rest of the logic for forming the element
</Input>
</Container>
The root tag and other tags in the XML are dynamic. The main objective behind the transformation is to convert the incoming XML elements and attributes to another language [like : Spanish] based on the value in the dictionary xml. Similar to the post