Difference between revisions of "XQuery 3.1"
Line 45: | Line 45: | ||
* Support for JSON: <code>fn:json-doc</code>, <code>fn:parse-json</code> | * Support for JSON: <code>fn:json-doc</code>, <code>fn:parse-json</code> | ||
* Comparison of <code>xs:hexBinary</code> and <code>xs:base64Binary</code> items | * Comparison of <code>xs:hexBinary</code> and <code>xs:base64Binary</code> items | ||
− | * <code>fn:collation-key</code>, <code>fn:parse-ietf-date</code>, <code>map:for-each-entry</code> | + | * <code>fn:collation-key</code>, <code>fn:load-module</code>, <code>fn:parse-ietf-date</code>, <code>fn:transform</code>, <code>map:for-each-entry</code> |
* <code>format-number</code>: support for scientific notation | * <code>format-number</code>: support for scientific notation | ||
Revision as of 10:33, 7 August 2014
This article is part of the XQuery Portal. It summarizes the new features of the XQuery 3.1 Working Draft that are already supported by BaseX.
Contents
Maps
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 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 xs:untypedAtomic
, and they will never be the xs:float
or xs:double
value NaN
.
The function call map:get($map, $key)
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 function($key as xs:anyAtomicType) as item()*
. Calling the function has the same effect as calling the get
function: the expression $map($key)
returns the same result as map:get($map, $key)
. For example, if $books-by-isbn
is a map whose keys are ISBNs and whose associated values are book
elements, then the expression $books-by-isbn("0470192747")
returns the 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 fn:map($f, $seq)
to extract all bound values from a map:
let $map := map { 'foo': 42, 'bar': 'baz', 123: 456 } return fn:map($map, map:keys($map))
This returns some permutation of (42, 'baz', 456)
.
Like all other values, maps are immutable. For example, the map:remove
function creates a new map by removing an entry from an existing map, but the existing map is not changed by the operation.
Like sequences, maps 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.
Because a map is a function item, functions that apply to functions also apply to maps. A map is an anonymous function, so fn:function-name
returns the empty sequence; fn:function-arity
always returns 1
.
Maps may be compared using the 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 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 fn:deep-equal
function.
The Map Module describes all map functions.
Functions
The following functions of the XQuery 3.1 Functions and Operators Working Draft have already been implemented:
fn:contains-token
, map:contains
, map:entry
, map:get
, map:keys
, map:new
, map:remove
New signatures have been added for the following functions:
fn:tokenize
Pending Features
The following features and functions will be available soon:
- Support for arrays: data structure, functions
- Support for JSON:
fn:json-doc
,fn:parse-json
- Comparison of
xs:hexBinary
andxs:base64Binary
items fn:collation-key
,fn:load-module
,fn:parse-ietf-date
,fn:transform
,map:for-each-entry
format-number
: support for scientific notation
Changelog
Introduced with Version 8.0.