Am 04.04.2022 um 13:00 schrieb Markus Elfring:
With XQuery 3.0, a group by clause was introduced [1, 2]. I can be applied to all data structures including arrays (“sequences” are the most basic data structure in XQuery, though).
I am looking for further hints in this software design area.
The following script got parsed.
declare option output:method "csv"; declare option output:csv "header=yes, separator=|"; let $results := for $x in //test_data/product return array { fn:count($x/contributor), $x/id/data() }
for $x in $results let $count := $x[1]
Perhaps you want
$x(1)
here to access the first item in the array $x?
let $incidence := fn:count($count) group by $count order by $incidence descending return
<csv> <record> <contributor_count>{$count}</contributor_count> <incidence>{$incidence}</incidence> </record> </csv>
But I stumble on the message “[XPTY0004] Item expected, sequence found: (1, "123").” from the query evaluation. https://docs.basex.org/wiki/XQuery_Errors#Type_Errors
Do you find the presented data processing approach reasonable (in principle)?
Regards, Markus