Skip to content

Instantly share code, notes, and snippets.

@mblakele
Created November 6, 2011 00:58
Show Gist options
  • Save mblakele/1342282 to your computer and use it in GitHub Desktop.
Save mblakele/1342282 to your computer and use it in GitHub Desktop.
W3C XQuery 3.0 - Group By Use Cases Q1, using map:map
<sales-qty-by-product>{
let $m := map:map()
let $build :=
for $sales in doc("sales-records.xml")/*/record
let $pname := $sales/product-name
return map:put(
$m, $pname, sum((
map:get($m, $pname),
$sales/qty)))
for $pname in map:keys($m)
order by $pname
return
<product name="{$pname}">{
map:get($m, $pname) }</product>
}</sales-qty-by-product>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment