Changes

Jump to navigation Jump to search
242 bytes removed ,  16:32, 6 August 2014
A map is an additional kind of item. It comprises a collation and a set of entries. Each entry comprises a key which is an arbitrary atomic value, and an arbitrary sequence called the associated value. Within a map, no two entries have the same key, when compared using the {{Code|eq}} operator under the map's collation. It is not necessary that all the keys should be mutually comparable (for example, they can include a mixture of integers and strings). Key values will never be of type {{Code|xs:untypedAtomic}}, and they will never be the {{Code|xs:float}} or {{Code|xs:double}} value {{Code|NaN}}.
The function call <code>[[Map Module#map:get|map:get($map, $key)]]</code> can be used to retrieve the value associated with a given key.
A ''map'' can also be viewed as a function from keys to associated values. To achieve this, a map is also a function item. The function corresponding to the map has the signature {{Code|function($key as xs:anyAtomicType) as item()*}}. Calling the function has the same effect as calling the {{Code|get}} function: the expression {{Code|$map($key)}} returns the same result as {{Code|map:get($map, $key)}}. For example, if {{Code|$books-by-isbn}} is a map whose keys are ISBNs and whose associated values are {{Code|book}} elements, then the expression {{Code|$books-by-isbn("0470192747")}} returns the {{Code|book}} element with the given ISBN. The fact that a map is a function item allows it to be passed as an argument to higher-order functions that expect a function item as one of their arguments. As an example, the following query uses the higher-order function {{Code|fn:map($f, $seq)}} to extract all bound values from a ''map'':
Maps may be compared using the {{Code|fn:deep-equal}} function. The semantics for this function are extended so that when two items are compared, at any level of recursion, the items compare equal if they are both maps, if both use the same collation, if both contain the same set of keys (compared using the {{Code|eq}} operator), without regard to ordering, and if for each key that is present in both maps, the associated values are deep-equal. When comparing maps, the maps' collation is used rather than the collation supplied as an argument to the {{Code|fn:deep-equal}} function.
 
Some examples use the ''map'' {{Code|$week}} defined as:
<pre class="brush:xquery">
declare variable $week as map(*) := map {
0: "Sonntag",
1: "Montag",
2: "Dienstag",
3: "Mittwoch",
4: "Donnerstag",
5: "Freitag",
6: "Samstag"
};
</pre>
The [[Map Module]] describes all map functions.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu