Changes

Jump to navigation Jump to search
13,099 bytes added ,  22:34, 22 April 2011
Created page with "==map:collation== {| | width='90' valign='top' | '''Signatures''' | <code><strong>map:collation</strong>($map as map(*)) as xs:string</code><br/> |- | valign='top' | '''Summary''..."
==map:collation==
{|
| width='90' valign='top' | '''Signatures'''
| <code><strong>map:collation</strong>($map as map(*)) as xs:string</code><br/>
|-
| valign='top' | '''Summary'''
| <p>Returns the URI of the supplied map's collation.</p>
|-
| valign='top' | '''Rules'''
| The function <code>map:collation</code> returns the collation URI of the <emph>map</emph> supplied as <code>$input</code>.
|}
==map:contains==
{|
| width='90' valign='top' | '''Signatures'''
| <code><strong>map:contains</strong>($map as map(*), $key as item()) as xs:boolean</code><br/>
|-
| valign='top' | '''Summary'''
| <p>Tests whether a supplied map contains an entry for a given key.</p>
|-
| valign='top' | '''Rules'''
| The function <code>map:contains</code> returns true if the <em>map</em> supplied as <code>$map</code> contains an entry with a key equal to the supplied value of <code>$key</code>; otherwise it returns false. The equality comparison uses the map's collation; no error occurs if the map contains keys that are not comparable with the supplied <code>$key</code>.
If the supplied key is <code>xs:untypedAtomic</code>, it is converted to <code>xs:string</code>. If the supplied key is the <code>xs:float</code> or <code>xs:double</code> value <code>NaN</code>, the function returns false.
<pre class="brush:xquery">let $week := map{0:="Sonntag", 1:="Montag", 2:="Dienstag", 3:="Mittwoch",
4:="Donnerstag", 5:"Freitag", 6:"Samstag"}</pre>
|-
| valign='top' | '''Examples'''
|
The expression <code>map:contains($week, 2)</code> returns <code>true()</code>.<br/>
The expression <code>map:contains($week, 9)</code> returns <code>false()</code>.<br/>
The expression <code>map:contains(map{}, "xyz")</code> returns <code>false()</code>.<br/>
The expression <code>map:contains(map{"xyz":=23}, "xyz")</code> returns <code>true()</code>.<br/>
|}
==map:entry==
{|
| width='90' valign='top' | '''Signatures'''
| <code><strong>map:entry</strong>($key as item(), $value as item()*) as map(*)</code><br/>
|-
| valign='top' | '''Summary'''
| <p>The function <code>map:entry</code> returns a new <em>map</em> containing a single entry. The collation of the new map is the the default collation from the static context. The key of the entry in the new map is <code>$key</code>, and its associated value is <code>$value</code>.</p>
|-
| valign='top' | '''Rules'''
| If the supplied key is <code>xs:untypedAtomic</code>, it is converted to <code>xs:string</code>. If the supplied key is the <code>xs:float</code> or <code>xs:double</code> value <code>NaN</code>, the supplied <code>$map</code> is returned unchanged.
The function <code>map:entry</code> is intended primarily for use in conjunction with the function <code>map:new</code>. For example, a map containing seven entries may be constructed like this:

<pre class="brush:xquery">
map:new((
map:entry("Su", "Sunday"),
map:entry("Mo", "Monday"),
map:entry("Tu", "Tuesday"),
map:entry("We", "Wednesday"),
map:entry("Th", "Thursday"),
map:entry("Fr", "Friday"),
map:entry("Sa", "Saturday")
))
</pre>

Unlike the <code>map{...}</code> expression, this technique can be used to construct a map with a variable number of entries, for example:
<pre class="brush:xquery">map:new(for $b in //book return map:entry($b/isbn, $b))</pre>
|-
| valign='top' | '''Examples'''
| The expression <code>map:entry("M", "Monday")</code> returns <code>map{"M":="Monday"}</code>.
|}
==map:get==
{|
| width='90' valign='top' | '''Signatures'''
| <code><strong>map:get</strong>($map as map(*), $key as item()) as item()*</code><br/>
|-
| valign='top' | '''Summary'''
| <p>Returns the value associated with a supplied key in a given map.</p>
|-
| valign='top' | '''Rules'''
| The function <code>map:get</code> attempts to find an entry within the <em>map</em> supplied as <code>$input</code> that has a key equal to the supplied value of <code>$key</code>. If there is such an entry, it returns the associated value; otherwise it returns an empty sequence. The equality comparison uses the map's collation; no error occurs if the map contains keys that are not comparable with the supplied <code>$key</code>. If the supplied key is <code>xs:untypedAtomic</code>, it is converted to <code>xs:string</code>. If the supplied key is the <code>xs:float</code> or <code>xs:double</code> value <code>NaN</code>, the function returns an empty sequence.
A return value of <code>()</code> from <code>map:get</code> could indicate that the key is present in the map with an associated value of <code>()</code>, or it could indicate that the key is not present in the map. The two cases can be distinguished by calling <code>map:contains</code>.
Invoking the <em>map</em> as a function item has the same effect as calling <code>get</code>: that is, when <code>$map</code> is a map, the expression <code>$map($K)</code> is equivalent to <code>get($map, $K)</code>. Similarly, the expression <code>get(get(get($map, 'employee'), 'name'), 'first')</code> can be written as <code>$map('employee')('name')('first')</code>.
<pre class="brush:xquery">let $week := map{0:="Sonntag", 1:="Montag", 2:="Dienstag", 3:="Mittwoch",
4:="Donnerstag", 5:"Freitag", 6:"Samstag"}</pre>
|-
| valign='top' | '''Examples'''
|
The expression <code>map:get($week, 4)</code> returns <code>"Donnerstag"</code>.<br/>
The expression <code>map:get($week, 9)</code> returns <code>()</code>. <em>(When the key is not present, the function returns an empty sequence.).</em><br/>
The expression <code>map:get(map:entry(7,())), 7)</code> returns <code>()</code>. <em>(An empty sequence as the result can also signify that the key is present and the associated value is an empty sequence.).</em><br/>
|}
==map:keys==
{|
| width='90' valign='top' | '''Signatures'''
| <code><strong>map:keys</strong>($map as map(*)) as xs:anyAtomicType*</code><br/>
|-
| valign='top' | '''Summary'''
| <p>Returns a sequence containing all the key values present in a map.</p>
|-
| valign='top' | '''Rules'''
| The function <code>map:keys</code> takes any <emph>map</emph> as its <code>$input</code> argument and returns the keys that are present in the map as a sequence of atomic values, in implementation-dependent order.
|-
| valign='top' | '''Examples'''
| The expression <code>map:keys(map{1:="yes", 2:="no"})</code> returns some permutation of <code>(1,2)</code>. <em>(The result is in implementation-dependent order.).</em><br/>
|}
==map:new==
{|
| width='90' valign='top' | '''Signatures'''
| <code><strong>map:new</strong>() as map(*)</code><br/><code><strong>map:new</strong>($maps as map(*)*) as map(*)</code><br/><code><strong>map:new</strong>($maps as map(*)*, $coll as xs:string) as map(*)</code><br/>
|-
| valign='top' | '''Summary'''
| <p>Creates a new map: either an empty map, or a map that combines entries from a number of existing maps.</p>
|-
| valign='top' | '''Rules'''
| The function <code>map:new</code> constructs and returns a new map. The zero-argument form of the function returns an empty <em>map</em> whose collation is the default collation in the static context. It is equivalent to calling the one-argument form of the function with an empty sequence as the value of the first argument.
The one-argument form of the function returns a <em>map</em> that is formed by combining the contents of the maps supplied in the <code>$input</code> argument. It is equivalent to calling the two-argument form of the function with the default collation from the static context as the second argument.
The two-argument form of the function returns a <em>map</em> that is formed by combining the contents of the maps supplied in the <code>$input</code> argument. The collation of the new map is the value of the <code>$collation</code> argument. The supplied maps are combined as follows:
<ol>
<li>
<p>
There is one entry in the new map for each distinct key value
present in the union of the input maps, where keys are considered
distinct according to the rules of the <code>distinct-values</code>
function with <code>$collation</code> as the collation.
</p>
</li>
<li>
<p>
The associated value for each such key is taken from the last
map in the input sequence <code>$input</code> that contains an
entry with this key. If this map contains more than one entry with
this key (which can happen if its collation is different from that
of the new map) then it is <em>implementation-dependent</em>
which of them is selected.
</p>
</li>
</ol>
There is no requirement that the supplied input maps should have the same or compatible types. The type of a map (for example <code>map(xs:integer, xs:string)</code>) is descriptive of the entries it currently contains, but is not a constraint on how the map may be combined with other maps.
<pre class="brush:xquery">let $week := map{0:="Sonntag", 1:="Montag", 2:="Dienstag",
3:="Mittwoch", 4:="Donnerstag", 5:"Freitag", 6:"Samstag"}</pre>
|-
| valign='top' | '''Examples'''
|
The expression <code>map:new()</code> returns <code>map{}</code>. <em>(Returns an empty map, whose collation is the default collation from the static context).</em><br/>
The expression <code>map:new(())</code> returns <code>map{}</code>. <em>(Returns an empty map, whose collation is the default collation from the static context).</em><br/>
The expression <code>map:new(map:entry(0, "no"), map:entry(1, "yes"))</code> returns <code>map{0:="no", 1:="yes"}</code>. <em>(Returns a map with two entries; the collation of the map is the default collation from the static context).</em><br/>
The expression <code>map:new(map:entry(0, "no"), map:entry(1, "yes"))</code> returns <code>map{0:="no", 1:="yes"}</code>. <em>(Returns a map with two entries; the collation of the map is the default collation from the static context).</em><br/>
The expression <code>map:new(($week, map{7:"Unbekannt"}))</code> returns <code>map{0:="Sonntag", 1:="Montag", 2:="Dienstag", 3:="Mittwoch", 4:="Donnerstag", 5:"Freitag", 6:"Samstag", 7:"Unbekannt"}</code>. <em>(The value of the existing map is unchanged; a new map is created containing all the entries from <code>$week</code>, supplemented with a new entry.).</em><br/>
The expression <code>map:new(($week, map{6:"Sonnabend"}))</code> returns <code>map{0:="Sonntag", 1:="Montag", 2:="Dienstag", 3:="Mittwoch", 4:="Donnerstag", 5:"Freitag", 6:"Sonnabend"}</code>. <em>(The value of the existing map is unchanged; a new map is created containing all the entries from <code>$week</code>, with one entry replaced by a new entry. Both input maps contain an entry with the key value <code>6</code>; the one used in the result is the one that comes last in the input sequence.).</em><br/>
The expression <code>map:new((map{"A":=1}, map{"a:=2"}), "http://collation.example.com/caseblind")</code> returns <code>map{"a":=2}</code>. <em>(Assuming that the keys of the two entries are equal under the rules of the chosen collation, only one of the entries can appear in the result; the one that is chosen is the one from the last map in the input sequence. If both entries were in the same map, it would be implementation-dependent which was chosen.).</em><br/>
|}
==map:remove==
{|
| width='90' valign='top' | '''Signatures'''
| <code><strong>map:remove</strong>($map as map(*), $key as item()) as map(*)</code><br/>
|-
| valign='top' | '''Summary'''
| <p>Constructs a new map by removing an entry from an existing map.</p>
|-
| valign='top' | '''Rules'''
| The function <code>map:remove</code> returns a new <em>map</em>. The collation of the new map is the same as the collation of the map supplied as <code>$map</code>. The entries in the new map correspond to the entries of <code>$map</code>, excluding any entry whose key is equal to <code>$key</code>.
No failure occurs if the input map contains no entry with the supplied key; the input map is returned unchanged
<pre class="brush:xquery">let $week := map{0:="Sonntag", 1:="Montag", 2:="Dienstag",
3:="Mittwoch", 4:="Donnerstag", 5:"Freitag", 6:"Samstag"}</pre>
|-
| valign='top' | '''Examples'''
| The expression <code>map:remove($week, 4)</code> returns <code>map{0:="Sonntag", 1:="Montag", 2:="Dienstag", 3:="Mittwoch", 5:"Freitag", 6:"Samstag"}</code>.<br/>
The expression <code>map:remove($week, 23)</code> returns <code>map{0:="Sonntag", 1:="Montag", 2:="Dienstag", 3:="Mittwoch", 4:="Donnerstag", 5:"Freitag", 6:"Samstag"}</code>.<br/>
|}
==map:size==
{|
| width='90' valign='top' | '''Signatures'''
| <code><strong>map:size</strong>($map as map(*)) as xs:integer</code><br/>
|-
| valign='top' | '''Summary'''
| <p>Returns a the number of entries in the supplied map.</p>
|-
| valign='top' | '''Rules'''
| The function <code>map:size</code> takes any <em>map</em> as its <code>$input</code> argument and returns the number of entries that are present in the map.
|-
| valign='top' | '''Examples'''
| The expression <code>map:size(map:new())</code> returns <code>0</code>.<br/> The expression <code>map:size(map{"true":=1, "false":0})</code> returns <code>2</code>.<br/>
|}
editor, reviewer
33

edits

Navigation menu