diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml index 73e77229c..2b053cc3d 100644 --- a/specifications/xpath-functions-40/src/xpath-functions.xml +++ b/specifications/xpath-functions-40/src/xpath-functions.xml @@ -8883,6 +8883,8 @@ return Other Operations on Maps + +

This section is non-normative.

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 @@ -8893,6 +8895,25 @@ return

There is no function or operator to atomize a map or convert it to a string (other than fn:serialize, which can be used to serialize some maps as JSON texts).

+

XPath 4.0 defines a number of syntactic constructs that operate on maps. These all have equivalents + in the function library:

+ + +

The expression {} creates an empty map. This is equivalent to the + effect of the data model primitive dm:empty-map(). Using user-visible functions + the same can be achieved by calling map:build(()), map:of-pairs(()), + or map:merge(()).

+

The map constructor { K1 : V1, K2 : V2, + ... , K/n : V/n } is equivalent to + map:merge((map:entry(K1, V1), map:entry(K1, V1), ..., map:entry(K/n, V/n)), {"duplicates":"reject"})

+

The lookup expression $map?* is equivalalent to map:values($map).

+

The lookup expression $map?K, where K is a key value, is equivalent to + map:get($map, K)

+

The expression for key $k value $v in $map return EXPR is equivalent to the function + call map:for-each($map, fn($k, $v) { EXPR }).

+ +
+ @@ -9064,55 +9085,42 @@ return
- Additional Operations on Arrays + Other Operations on Arrays

This section is non-normative.

+ +

Arrays may be compared using the fn:deep-equal function.

+

The XPath language provides explicit syntax for certain operations on arrays. - These constructs can also be specified in terms of function primitives:

+ These constructs can all be specified in terms of function primitives:

- - Singleton Arrays - -

array { $sequence } constructs an array whose members - are the items in $sequence. Every member of this array will - be a singleton item. This can be defined as - array:join($sequence ! array { . }).

-

[E1, E2, E3, ..., En] constructs an array in which - E1 is the first member, E2 is the second member, - and so on. The result is equivalent to the expression - array:join(([ E1 ], [ E2 ], ... [ En ])).

-

The lookup expression $array?* is equivalent to - array:split($array)?*.

-

The lookup expression $array?$N, where $N - is an integer within the bounds of the array, is equivalent to - array:split($array)[$N]?*.

-

Similarly, applying the array as a function, $array($N), - is also equivalent to - array:split($array)[$N]?*

-
-
- - Value Maps - -

array { $sequence } constructs an array whose members - are the items in $sequence. Every member of this array will - be a singleton item. This can be defined as - array:of-members($sequence ! { 'value': . }).

-

[E1, E2, E3, ..., En] constructs an array in which - E1 is the first member, E2 is the second member, - and so on. The result is equivalent to the expression - array:of-members(({ 'value': E1 }, { 'value': E2 }, - { 'value': E3 }, ... { 'value': En })).

-

The lookup expression $array?* is equivalent to - array:members($array) ! ?value.

-

The lookup expression $array?$N, where $N - is an integer within the bounds of the array, is equivalent to - array:members($array)[$N]?value.

-

Similarly, applying the array as a function, $array($N), - is also equivalent to - array:members($array)[$N]?value

-
-
+ +

An empty array can be constructed using either of the expressions + [] or array{}. The effect is the same as the data model primitive + dm:empty-array(()). Using user-visible functions it can be achieved + by calling array:build(()) or array:of-members(()).

+

The expression array { $sequence } constructs an array whose members + are the items in $sequence. Every member of this array will + be a singleton item. The effect is the same as + array:build($sequence).

+

The expression [E1, E2, E3, ..., E/n] constructs an array in which + E1 is the first member, E2 is the second member, + and so on. The result is equivalent to the expression + [] => array:append(E1) => array:append(E2) => ... => array:append(E/n))).

+

The lookup expression $array?* returns the + sequence concatenation + of the members of the array. It is equivalent to calling + array:fold-left($array, (), fn($result, $next){ $result, $next }).

+

The lookup expression $array?$N, where $N + is an integer within the bounds of the array, is equivalent to + array:get($array, $N).

+

Similarly, applying the array as a function, $array($N), + is also equivalent to array:get($array, [$N])

+

The expression for member $m in $array return EXPR + is equivalent to array:for-each($array, fn($m){ EXPR }).

+
+ +