Getting "count: Parameter must be a NodeSet" trying to count nodes with a specific numeric value
I'开发者_C百科m using Perl's XML::XPath package in a small script. I'm pretty sure I have an xpath problem, not something specific to that package.
My test data is the following:
<stuff>
<things>
<thing>
<widgets>
<widget>
<junk>
<value>0</value>
</junk>
</widget>
<widget>
<junk>
<value>9.0</value>
</junk>
</widget>
</widgets>
</thing>
</things>
</stuff>
The expression I'm using is:
//thing[count(number(widgets/widget/junk/value/text())=0)=0]
When I run this, it fails with "count: Parameter must be a NodeSet".
the following code within the count()
returns a boolean which is not a node:
number(widgets/widget/junk/value/text())=0
This is not allowed in XPath 1.0
If you want to select <thing/>
elements containing no <value/>
element with value 0 you can use:
//thing[not(
widgets/widget/junk/value[number(text())=0]
)]
精彩评论