Changes

Jump to navigation Jump to search
3,224 bytes added ,  22:44, 22 April 2011
no edit summary
<p>This module contains [[Querying#Functions|XQuery Functions]] for manipulating maps.</p>
<p>All functions are preceded by the <code>map:</code> prefix, which is linked to the <code>http://www.w3.org/2005/xpath-functions/map</code> namespace.</p>
<p>A map is an additional kind of item.</p>
<p>A map 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</code> 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</code>, and they will never be the <code>xs:float</code> or <code>xs:double</code> value <code>NaN</code>.</p> <p>The function call <code>map:get($map, $key)</code> can be used to retrieve the value associated with a given key.</p>
<p>A <em>map</em> 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:anyAtomicValue) as item()*</code>. Calling the function has the same effect as calling the <code>get</code> function: the expression <code>$map($key)</code> returns the same result as <code>get($map, $key)</code>. For example, if <code>$books-by-isbn</code> is a map whose keys are ISBNs and whose assocated values are <code>book</code> elements, then the expression <code>$books-by-isbn("0470192747")</code> returns the <code>book</code> 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.</p>
<p>Like all other values, <em>maps</em> are immutable. For example, the <code>map:remove</code> function creates a new map by removing an entry from an existing map, but the existing map is not changed by the operation.</p>
<p>Like sequences, <em>maps</em> have no identity. It is meaningful to compare the contents of two maps, but there is no way of asking whether they are "the same map": two maps with the same content are indistinguishable.</p>
<p>Because a map is a function item, functions that apply to functions also apply to maps. A map is an anonymous function, so <code>fn:function-name</code> returns the empty sequence; <code>fn:arity</code> always returns <code>1</code>.</p>
<p>Maps may be compared using the <code>fn:deep-equal</code> 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</code> 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</code> function.</p>
<p>There is no operation to atomize a map or convert it to a string.</p>
 
==map:collation==
{|
editor, reviewer
33

edits

Navigation menu