delete nodes from xml file having duplicate ID using xsl



I have xml as below:



<panel id="MainPanel" x="0" y="0" w="100%" h="100%" backgroundcolor="green" >

<panel id="somepanel" x="0" y="130" w="100%" h="PANEL_ALIGN" backgroundcolor="red" >
<panel id="nextpanel" x="0" y="130" w="100%" h="PANEL_ALIGN" backgroundcolor="red" >
<table id="TestPanel" x="1%" y="20" w="98%" h="PANEL_ALIGN""></table>
<table id="TestPanel" x="1%" y="20" w="98%" h="PANEL_ALIGN""></table>
<table id="TestPanel2" x="1%" y="20" w="98%" h="PANEL_ALIGN""></table>
</panel>
</panel>


Expected is:



<panel id="MainPanel" x="0" y="0" w="100%" h="100%" backgroundcolor="green" >

<panel id="somepanel" x="0" y="130" w="100%" h="PANEL_ALIGN" backgroundcolor="red" >
<panel id="nextpanel" x="0" y="130" w="100%" h="PANEL_ALIGN" backgroundcolor="red" >
<table id="TestPanel" x="1%" y="20" w="98%" h="PANEL_ALIGN""></table>
<table id="TestPanel2" x="1%" y="20" w="98%" h="PANEL_ALIGN""></table>
</panel>
</panel>


I use below xsl to remove table node but it removes all table node.



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

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

<xsl:template
match="table"/>
</xsl:stylesheet>


Could anyone help , as i dont knwo much of xslt.


No comments:

Post a Comment