Project

Profile

Help

Bug #1981 » group_by_map.xq

Ed Gimzewski, 2014-01-16 01:25

 
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";

declare option output:method "text";
declare option output:encoding "utf-8";

let $coll_of_maps := ( map{"a":=1,"b":=2}, map{"a":=1,"b":=3}, map {"a":=2,"b":=2}, map {"a":=2,"b":=4},map {"a":=3,"b":=2})
(: this creates an exception if returned :)
let $grouping_not_trapped :=
for $m in $coll_of_maps
let $a := $m('a')
group by $a
return map { "key":=$a , "members":=$m }
(: this same code trapped works OK :)
let $grouping_trapped:=
try{
for $m in $coll_of_maps
let $a := $m('a')
group by $a
return map { "key":=$a , "members":=$m }
}catch * {
map {"err":= $err:description }
}

(: edit to return $grouping_not_trapped to see it fail :)
return serialize-json($grouping_trapped)
(1-1/2)