Hi Markus,
although I do not quite understand your description (why should I care for the 
representation of the map I construct?), it may be that one piece of 
information is useful to you, as it is not obvious from the spec: it's about 
how to construct a map dynamically, that is, 
(1) when the keys are not known beforehand, (2) and/or when the entry values 
are assigned in "iterations" of a FLWOR expression
(Especially (2) might be what puzzles you.)
(1) and (2) can't be accomplished when using the map constructor expression, 
like this: basex "map{'x':1, 'y': false()}" 
The trick consists of using a combination of the functions map:merge() [1] and 
map:entry() [2].
So summarize, the code constructing the map entries is the argument of function 
map:merge().This code may for example be (most often is) a FLWOR expression. In 
this code, each entry is constructed by a call of function map:entry(). For a 
tiny example see below.
Kind regards,Hans-Jürgen
PS: Tiny example demonstrating the construction of maps via map:merge() & 
map:entry().
(: Creates a map with one entry for each element name   encountered in the 
input document. The entry value   is the number of elements with that name. As 
the   map keys are not known in advance, map:merge() is   used. :)map:merge(    
for $elem in //*    group by $name := $elem/local-name(.)    return 
map:entry($name, count($elem)))
[1] https://www.w3.org/TR/xpath-functions-31/#func-map-merge[2] 
https://www.w3.org/TR/xpath-functions-31/#func-map-entry





    Am Mittwoch, 25. Mai 2022, 16:59:48 MESZ hat Markus Elfring 
<markus.elfr...@web.de> Folgendes geschrieben:  
 
 Hello,

I would like to construct a map structure based on a dynamic selection by
the means of a FLWOR expression.
https://www.w3.org/TR/2017/REC-xquery-31-20170321/#id-maps

The keys and associated values should be presented as a CSV-like file by
a subsequent data processing step.

Can it become easier to find existing XQuery script examples for such an use 
case?

Regards,
Markus
  

Reply via email to