Reputation: 30
I am trying to count number of count number of element where all the value element are 0. I am using XSLT1.0 I have used
count(//element[value ='0'])
but it gives count if one of the value is 0 (so the count comes to 3) not all the value are 0(count should be 1).
<root>
<element>
<value>1</value>
<value>0</value>
<value>0</value>
</element>
<element>
<value>0</value>
<value>0</value>
<value>0</value>
</element>
<element>
<value>0</value>
<value>0</value>
<value>1</value>
</element>
</root>
I can use
count(//element[value !='0'])
to count elements that are not zero but looking for a solution that can count 0.
Thanks.
Upvotes: 0
Views: 38
Reputation: 29052
Try this XPath-1.0 expression. It subtracts the count of the value
s which are 0
from the overall count of value
s:
count(//element[count(value) - count(value[text()='0']) = 0])
Upvotes: 1