I am trying to count the occurrences of an XML structure in BaseX.
declare variable $a := 0;
for $node in db:open("My_DB")/my/xml//path
$a += 1
return $a
When running this, BaseX returns the error: Incomplete FLWOR expression: expecting 'return'.
I know that I can count with this simple function:
count(db:open("My_DB")/my/xml//path)
But there are two reasons zhy I am trying to do this with a for loop:
- I have been told by my supervisor that a for loop is faster
- In the future I may want to execute more operations per hit (in the for loop)
So the question is: how can I count elements in a for loop with XQuery using BaseX.