Xquery-计数元素

时间:2018-11-30 02:53:24

标签: xquery

如何返回字符串序列?

1 个答案:

答案 0 :(得分:2)

自2014年以来的XQuery支持您可以使用的group by子句:

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

如果没有XQuery 3支持,则可以使用

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