Given the following XQuery: let $input := <root> <item><key>a</key><value>1</value></item> <item><key>b</key><value>2</value></item> <item><key>b</key><value>3</value></item> </root>
let $map := map:merge(( map:entry(1, "A"), map:entry(2, "B"), map:entry(3, "C") )) for $result in $input/* let $key := $result/key/text() let $value := $result/value/text() group by $key return map:get($map, $key) When trying to execute that query, I get the error "Item expected, sequence found: (map {1:"A",2:"B",3:"C"}, map {1:"A",2:"B",3:"C"}). But why does it group the map? It isn't part of that for-loop but rather some kind of global variable. Or do I misunderstand the "group by" clause? I only expect the $value to be grouped which results in a sequence. Thanks, Alex