I’m using XSLT to restructure an XML file. The following code copies all child nodes to a new XML file:
<!--Add all child elements of the zzz node--> <xsl:template match='zzz'> <Trade> <xsl:attribute name='ID'> <xsl:value-of select='TradeId' /> </xsl:attribute> <xsl:copy-of select='*'></xsl:copy-of> </Trade> </xsl:template>
I would like to modify the code so that it puts the nodes into a specific namespace that is not in the source document. What do I need to change?
The previous two answers (by teun and Craig Bovis) are not correct — see my comments to each of these.
The corect way to move a given element to a new namespace involves re-creating this element as shown below:
When this transformation is applied on the following source XML document:
the required result is produced: