XSL to get only elements which have no childs
-
Hi, I make my question after some research in web without any clear response to my problem. I have the following XML and I need to apply an XSL transformation to get only nodes which haven't child. Input :
Expected output :
Something like this should work:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Root_Element">
<xsl:element name="{name()}">
<xsl:apply-templates select="*|@*"/>
</xsl:element>
</xsl:template><xsl:template match="\*"> <xsl:choose> <xsl:when test="count(\*) = 0"> <xsl:element name="{name()}"> <xsl:apply-templates select="@\*"/> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="\*" /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="@\*"> <xsl:attribute name="{name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>
</xsl:stylesheet>
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Something like this should work:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Root_Element">
<xsl:element name="{name()}">
<xsl:apply-templates select="*|@*"/>
</xsl:element>
</xsl:template><xsl:template match="\*"> <xsl:choose> <xsl:when test="count(\*) = 0"> <xsl:element name="{name()}"> <xsl:apply-templates select="@\*"/> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="\*" /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="@\*"> <xsl:attribute name="{name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>
</xsl:stylesheet>
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Something like this should work:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Root_Element">
<xsl:element name="{name()}">
<xsl:apply-templates select="*|@*"/>
</xsl:element>
</xsl:template><xsl:template match="\*"> <xsl:choose> <xsl:when test="count(\*) = 0"> <xsl:element name="{name()}"> <xsl:apply-templates select="@\*"/> </xsl:element> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="\*" /> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="@\*"> <xsl:attribute name="{name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>
</xsl:stylesheet>
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer