<xsl:template match="/>
<xsl:value-of select="count(//*[not(*) and normalize-space() != ''])" />
</xsl:template>
This repeats the entire XML tree through the descendant axis ( //), scans all element nodes ( *) that have no children ( not(*)) and contain data other than spaces ( normalize-space() != '').
The resulting node -set result is counted (and returns 4 in your case).
source
share