XSLT recursive copy part of xml and apply templates on that



I have next XML. next problem. I made templetes for children of weneedit node. and i need remove all exclude weneedit and his children. I can't apply template and make recursive copy together.



<?xml version="1.0" encoding="UTF-8"?>
<root>
<list>
<element>
<subelement>123</subelement>
</element>
<element>
<subelement>
<weneedit>
<andit>
<helpfultext>
</helpfultext>
</andit>
</weneedit>
</subelement>
</element>

</list>
<tag>
<rt>321</rt>
<tag>
</root>


I have tried do like that



<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="n:weneedit">
<xsl:copy-of select="parent::node()"/>
</xsl:template>


but works one or other template not together


i want to get something like this



<subelement>
<weneedit>
<andit>
<helpfultext>it was edited</helpfultext>
</andit>
</weneedit>
</subelement>

No comments:

Post a Comment