how to sum all of the count items in xquery

49 Views Asked by At
My problem is i want to display the count of all genre that is equals to actions

`

<videos genre="action" count="{
 for $videos in doc("videos.xml")/result/videos/video
 let $count := 0
  
  where $videos/genre ="action" 

 return count($videos/genre)
}"

`

`` but my result is this

the count is=1 1 1 i want the answer is equal to 3



im expecting a result that is 
<videos genre="action" count="3"><video>
1

There are 1 best solutions below

1
On

You are making it a bit too complicated; try something like:

<videos genre="action" count="{
count(doc("videos.xml")//video[.//genre[.="action"]])
}"/>

or, depending on the struture of you actual videos file, you can use instead

count(//video[.//.="action"])

Those should get you your expected output.