Dear Jean-Marc,
Welcome back!
Maps in XQuery are simple key/value pairs; neither keys nor values will be arranged in a specific order.
If you want to sort map by keys before outputting them, you can sort them in a second step:
let $map := map:merge(( map:entry(0.1, "Sunday"), map:entry(5.0, "Thursday"), map:entry(2.0, "Monday"), map:entry(3.0, "Wednesday"), map:entry(0.5, "Tuesday"), map:entry(6.0, "Friday"), map:entry(7.0, "Saturday") )) for $key in sort(map:keys($map)) return "* " || $key || ": " || $map($key)
Hope this helps, Christian
On Tue, Sep 26, 2017 at 11:29 AM, jean-marc Mercier jeanmarc.mercier@gmail.com wrote:
Hello BaseX team,
It has been a while since I last wrote to this mailing list ! Happy to report again :)
I have a strange behavior concerning map, it doesn't seem to sort as I expected. Is there any explanation ?
let $map as map(xs:double,xs:string) := map:merge(( map:entry(xs:double(0.1), "Sunday"), map:entry(xs:double(5.0), "Thursday"), map:entry(xs:double(2.0), "Monday"), map:entry(xs:double(3.0), "Wednesday"), map:entry(xs:double(0.5), "Tuesday"), map:entry(xs:double(6.0), "Friday"), map:entry(xs:double(7.0), "Saturday") )) return $map
output : map { 2: "Monday", 3: "Wednesday", 5: "Thursday", 6: "Friday", 7: "Saturday", 0.1: "Sunday", 0.5: "Tuesday" }
Cheers