I have the xml like this:
<definitions xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test">
</definitions>
which I need to convert like this:
<test xmlns:xxx="test.com" xmlns:yyy="test2.com" test="test">
</test>
I wrote an xslt like this:
<xsl:template match="definitions">
<xsl:element name="test">
<xsl:copy-of select="@*" />
</xsl:element>
</xsl:template>
this produces:
<test test="test">
</test>
but it doesnt contain xmlns:xxx="test.com" xmlns:yyy="test2.com"
namespaces why?
How can I copy along with namespaces also?
The namespaces have to be declared in your XSL file, too:
It doesn't contain the namespace declarations because they are not used anywhere - so the XSLT processor does not output them.
I don't see why you would want them - but if you insist, you could copy them explicitly:
Note that that it's not necessary to use
xsl:element
when the name of the element is known.It seems like that you just want to rename the element "definitions" to "test". You can use something like this.