I’ve got a sequence of values. They can all be equal… or not. So with XQuery I want to get the most frequent item in the sequence.
let $counter := 0, $index1 := 0
for $value in $sequence
if (count(index-of($value, $sequence)))
then
{
$counter := count(index-of($value, $sequence)) $index1 := index-of($value)
} else {}
I can’t make this work, so I suppose I’m doing something wrong.
Thanks in advance for any help you could give me.
Use:
Update, Dec. 2015:
This is notably shorter, though may not be too-efficient:
The shortest expression can be constructed for XPath 3.1:
And even shorter and copyable — using a one-character name: