Home > front end >  Xquery how to use count
Xquery how to use count

Time:04-10

<state>
<hospital>
<ambulances> 1 </ambulances>
</hospital>

<hospital>
<ambulances> 0 </ambulances>
</hospital>

<hospital>
<ambulances> 2 </ambulances>
</hospital>
</state>

I'm trying to do a count in Xquery 3.0 where I count all ambulances which are above 0

Blockquote

I've tried

for $i in doc("my.xml")//state let $x := $i//ambulances let $count := count(x != 0)

return {$count}

but my loops keeps executing in which it replies back with {1 , 1}

CodePudding user response:

I don't see the need for a FLOWR expression, a simple function call on the right path with e.g.

count(/state/hospital/ambulances[. > 0])

suffices.

  • Related