That didn't work either. It returns 8 for the first senario and 7 for the second senario.
Main Topics
Browse All TopicsI am trying to get a count of all descendant nodes for the current node that have text node values. For example, given the following xml, I would expect the value 1.
<FORM>
<FORM_VALUE1>afc</FORM_VAL
<ACTION/>
<FORM_NAME/>
<FORM_ITEM_NAME1/>
<FORM_IDENTIFIER/>
<NTRID/>
</FORM>
For the following xml, I would expect 0.
<FORM>
<FORM_VALUE1/>
<ACTION/>
<FORM_NAME/>
<FORM_ITEM_NAME1/>
<FORM_IDENTIFIER/>
<NTRID/>
</FORM>
I have tried a variety of different, solutions but I either always get back 0, or 7.
<xsl:element name="counter">
<xsl:value-of select="count($parentGroup
</xsl:element>
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I used the following simple XSLT against the XML I posted in http:#25127424 and get back two.
@locke_a,
I bet you are testing either in XML Spy or with a microsft XML parser,
but your solution is also counting white-space only text nodes.
Both XML Spy and msxml do this the wrong way,
they forget to count white-space only text nodes which both processors ,
since both processors erroneously consider those as non significant
Since you made it an XSLT2 stylesheet I bet you are using XML-Spy
Beware for Spy's XSLT2, it is not standardized enough, as you have just proven yourself
If I use your stylesheet with a conformant processor such as Saxon, I get <counter>7</counter> which is wrong
@trudyhlittle,
You ask for nodes, but I think you mean elements, not text nodes
I suggest that you should use "descendant::*" instead of "descendant::node()"
When checking whether something is empty, it is always good to normalize-space before,
just in order to avoid a single space or a single new line to be counted as a significant node
I believe this is the XPath you want
count(FORM/node()[string-l
or in case of elements only
count(FORM/*[string-length
translated to your example
<xsl:value-of select="count($parentGroup
cheers
Geert
Business Accounts
Answer for Membership
by: locke_aPosted on 2009-08-18 at 12:43:47ID: 25126801
Try:
ength() > 0])
count(FORM/node()[string-l