Reputation: 949
I am using XSLT to transform input XML to output XML. My requirement is I need to remove all empty tags from my output XML during XSLT transformation from input.
I tried the instructions given here
https://stackoverflow.com/questions/6648679/removing-empty-tags-from-xml-via-xslt
But probably this talks about the scenario where we are only writing an XSLT for removing the empty tags from an XML. In my case, I will have to eliminate the empty tags while transforming from input XML to output XML (In the same XSLT used for transformation). Can you please suggest me how to do it?
Upvotes: 0
Views: 524
Reputation: 167516
In XSLT 3 it might suffice to use xsl:where-populated
as a "wrapper" for the identity transformation in the match for elements:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="*">
<xsl:where-populated>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:where-populated>
</xsl:template>
<xsl:template match="foo"/>
</xsl:stylesheet>
Upvotes: 1