Changes

Jump to navigation Jump to search
18 bytes removed ,  10:39, 8 April 2020
no edit summary
This [[Module Library|XQuery Module]] contains functions for manipulating maps. [[XQuery 3.1#Maps|Maps ]] have been introduced with XQuery 3.1 and are described in detail in the [https://www.w3.org/TR/xpath-functions-31/#maps-and-arrays [XQuery Functions and Operators 3.1 specification]].
=Conventions=
Some examples use the ''map'' {{Code|$week}} defined as:
<pre classsyntaxhighlight lang="brush:xquery">
declare variable $week := map {
0: "Sun", 1: "Mon", 2: "Tue", 3: "Wed", 4: "Thu", 5: "Fri", 6: "Sat"
};
</presyntaxhighlight>
==map:contains==
The function {{Code|map:entry}} is intended primarily for use in conjunction with the function <code>[[#map:merge|map:merge]]</code>. For example, a map containing seven entries may be constructed like this:
<pre classsyntaxhighlight lang="brush:xquery">
map:merge((
map:entry("Sun", "Sunday"),
map:entry("Sat", "Saturday")
))
</presyntaxhighlight>
Unlike the <code>map { ... }</code> expression, this technique can be used to construct a map with a variable number of entries, for example:
<pre classsyntaxhighlight lang="brush:xquery">map:merge(for $b in //book return map:entry($b/isbn, $b))</presyntaxhighlight>
|-
| '''Examples'''
| '''Examples'''
|The following query adds the keys and values of all map entries and returns {{Code|(3,7)}}:
<pre classsyntaxhighlight lang="brush:xquery">
map:for-each(
map { 1: 2, 3: 4 },
function($key, $value) { $key + $value }
)
</presyntaxhighlight>
|}
* {{Code|map:merge((map:entry(0, "no"), map:entry(1, "yes")))}} creates <code>map { 0: "no", 1: "yes" }</code>.
* The following function adds a seventh entry to an existing map:
<pre classsyntaxhighlight lang="brush:xquery">
map:merge(($week, map { 7: "---" }))
</presyntaxhighlight>
* In the following example, the values of all maps are combined, resulting in a map with a single key (<code>map { "key": (1, 2, 3) }</code>):
<pre classsyntaxhighlight lang="brush:xquery">
map:merge(
for $i in 1 to 3 return map { 'key': $i },
map { 'duplicates': 'combine' }
)
</presyntaxhighlight>
|}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu