Maps in XQuery 3.1
Please note that maps are part of the XQuery 3.1 specification, which is still subject to change. eXist is trying to preserve backwards compatibility as far as possible. You may thus find that some apps are still using the older notation "key:=value" instead of "key:value" for the map constructor.
See the function documentation for a list of all functions.
Day of week
let $week := map {0: "Sonntag", 1: "Montag", 2: "Dienstag", 3: "Mittwoch", 4: "Donnerstag", 5: "Freitag", 6: "Samstag"}
return
$week(3)
Lookup operator
xquery version "3.0";
let $week := map
{"sunday": "Sonntag", "monday": "Montag", "tuesday": "Dienstag",
"wednesday": "Mittwoch", "thursday": "Donnerstag",
"friday": "Freitag", "saturday": "Samstag"}
return
$week?thursday
Map using date as key
<table class="table table-striped">
{
let $birthdays := map {
xs:date("1975-03-19") : "Uschi",
xs:date("1980-01-22") : "Verona",
xs:date("1960-06-14") : "Heinz",
xs:date("1963-10-21") : "Roland"
}
for $key in map:keys($birthdays)
let $name := $birthdays($key)
order by $name ascending
return
<tr>
<td>{$name}</td>
<td>{format-date($key, "[MNn] [D00], [Y0000]")}</td>
</tr>
}
</table>
map:for-each-entry
<table class="table table-striped">
{
let $birthdays := map {
xs:date("1975-03-19") : "Uschi",
xs:date("1980-01-22") : "Verona",
xs:date("1960-06-14") : "Heinz",
xs:date("1963-10-21") : "Roland"
}
return
map:for-each-entry($birthdays, function($date, $name) {
<tr>
<td>{$name}</td>
<td>{format-date($date, "[MNn] [D00], [Y0000]")}</td>
</tr>
})
}
</table>