0
votes

How to return a sequence of string?

1

1 Answers

2
votes

XQuery since 2014 supports a group by clause you can use:

for $dept at $pos in //building[year = '1900']/department
group by $key := $dept
order by $pos[1]
return ($key || ' ' ||  count($dept))

https://xqueryfiddle.liberty-development.net/gWcDMen

If you don't have XQuery 3 support you can use

let $dept := //building[year = '1900']/department
for $dist-dept in distinct-values($dept)
return 
    concat($dist-dept, ' ', count($dept[. = $dist-dept]))

https://xqueryfiddle.liberty-development.net/gWcDMen/1