tia_kamakshi
asked on
Count non empty nodes in XSL
Hi,
Using XSL how do we count non empty nodes
Like in below xml example If we have to count non empty CCC nodes
value should come 2
Please help me in xsl code
<AAA>
<BBB>
<CCC id="c1">CCC1</CCC>
<CCC id="c2">CCC2</CCC>
<CCC id="c20"/>
<CCC/>
</BBB>
</AAA>
Many Thanks
Using XSL how do we count non empty nodes
Like in below xml example If we have to count non empty CCC nodes
value should come 2
Please help me in xsl code
<AAA>
<BBB>
<CCC id="c1">CCC1</CCC>
<CCC id="c2">CCC2</CCC>
<CCC id="c20"/>
<CCC/>
</BBB>
</AAA>
Many Thanks
ASKER
Thanks for your quick response
I have modified my XML as below but value is not coming 3 this time
<?xml version="1.0" encoding="utf-8" ?>
<AAA>
<BBB>
<CCC id="c1">CCC1</CCC>
<CCC id="c2">CCC2</CCC>
<CCC id="c20">CCC3</CCC>
<CCC/>
</BBB>
</AAA>
Please help me fixing xsl
Thanks again
I have modified my XML as below but value is not coming 3 this time
<?xml version="1.0" encoding="utf-8" ?>
<AAA>
<BBB>
<CCC id="c1">CCC1</CCC>
<CCC id="c2">CCC2</CCC>
<CCC id="c20">CCC3</CCC>
<CCC/>
</BBB>
</AAA>
Please help me fixing xsl
Thanks again
ASKER
Also, I need count of nodes <CCC> which is non blank
Thanks again
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry - I was in a rush to a meeting.
I think Geert is on the right track. I assumed you wanted to count ALL nodes that contained text, not just certain elements. To accomplish this, try the following:
<xsl:template match="*">
<xsl:text>Text nodes: </xsl:text><xsl:value-of select="count(//text()[nor malize-spa ce()])"/>
</xsl:template>
I think Geert is on the right track. I assumed you wanted to count ALL nodes that contained text, not just certain elements. To accomplish this, try the following:
<xsl:template match="*">
<xsl:text>Text nodes: </xsl:text><xsl:value-of select="count(//text()[nor
</xsl:template>
ASKER
Many Thanks for your help
welcome
<xsl:value-of select="count(text())"/>
</xsl:template>