I need some help for an XSLT transformation.
My XML input looks like :
<ns0:X>
<ns0:Y>
<Z>
<TagA>Content</TagA>
<TagB>
<TagB1>Content Tag B1</TagB1>
<TagB2>Content Tag B2</TagB2>
</TagB>
</Z>
</ns0:Y>
</ns0:X>
I need to remove the 3 tags <X>
, <Y>
, and <Z>
and add a new root tag <root>
.
The result must be like this :
<root>
<TagA>Content</TagA>
<TagB>
<TagB1>Content Tag B1</TagB1>
<TagB2>Content Tag B2</TagB2>
</TagB>
</root>
Currently I can add the new <root>
tag but I can't remove <X>
, <Y>
, and <Z>
.
Thanks in advance for your help. YC
Trying to do an XSLT Transformation.
I expect the solution.
It might be as simple as:
<xsl:template match="/">
<root>
<xsl:copy-of select="//Z/child::node()"/>
</root>
</xsl:template>
However, this illustrates the danger of using one example as a specification. This might do the right thing with the example you have shown, but the wrong thing with other examples that differ from it, for example by not having an element named Z
.
Also it might do the wrong thing with namespaces. Your example has an undeclared namespace prefix, so it's not clear what your intentions are.