So when you attempt to print out <incidence>{$incidence}</incidence>, XQuery finds a sequence (1, 1, 1) instead of the value you want, 3.
Dear Tamara,
I found this test result surprising.
To get the count of $incidence, you could return <incidence>{count($incidence)}</incidence> instead.
My understanding is still evolving also for implementation details according to FLWOR expressions.
But since you're not using the IDs at all, placing them in a sequence of arrays first isn't necessary.
I imagined that I would need a subquery. Thus I found the specification of an identification relevant (for a moment).
You can skip that part like:
for $x in //test_data/product let $count := count($x/contributor) let $id := $x/id/data() group by $count let $incidence := count($id)
My knowledge was improvable also for desirable variable bindings.
order by $incidence descending return
<csv> <record> <contributor_count>{$count}</contributor_count> <incidence>{$incidence}</incidence> </record> </csv>
I thank you very much for the demonstration of a report approach which is working as expected finally.
Will similar use cases become interesting for further clarification?
Regards, Markus