I decided to open a new topic because in previous I did not precisly define what I'm expecting. My XML on input looks:
<tag5>
<addresses/>
<identifiedBaseServices/>
<sharedGroups>
<names></names>
<types></types>
</tag5>
<contain>
<attributes/>
<addresses/>
<identifiedBaseServices/>
<sharedGroups>
<names></names>
<types></types>
</sharedGroups>
</contain>
<smth>
<tag1></tag1>
<tag3> TEXT </tag3>
</smth>
All what I want is delete empty nodes except some which I explicit define. For example I don't want to remove
attributes,
So xml OUTPUT shoud looks:
<contain>
<attributes/>
</contain>
<smth>
<tag3> TEXT </tag3>
</smth>
I was looking for some solution, after few hours i got smth like:
<xsl:strip-space elements="*"/>
<xsl:template match="*[descendant::text() or descendant-or-self::*/@*[string()]]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="attributes[not(node())]" priority="1">
<xsl:copy>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(.//text() | .//@*)]"/>
</xsl:stylesheet>
It works almost fine but only then if eg. contain some data.When everything is null then that XSL code remove ALL empty tag...
Is anyone here who could help me? Thanks in advance..