diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml
index 748137ea5..624917ecc 100644
--- a/specifications/xpath-functions-40/src/function-catalog.xml
+++ b/specifications/xpath-functions-40/src/function-catalog.xml
@@ -22998,8 +22998,7 @@ xs:QName('xs:double')
The function There is one entry in the returned map for each distinct key present in the union
- of the input maps, where two keys are distinct if they are not the $maps
+ returns a map that is formed by combining the contents of the maps supplied in the $maps
argument.
If there are duplicate keys, that is, if two or more maps contain entries having the
$options
argument.
The definitive specification is as follows.
- -If the second argument is omitted or an empty sequence, the effect is the same as
- calling the two-argument function with an empty map as the value of $options
.
The $options
argument can be used to control the way in which duplicate keys are handled.
- The
In the event that two or more entries in the input maps have the
-
$options
.
+
+
+ The $options
argument takes the same values (with the same meanings)
+ as the map:merge
, the default for duplicate keys is use-first
.
The difference is for backwards compatibility reasons.
With the default options, when duplicate entries occur:
+A single entry is created by combining the values of the duplicates,
- in a way determined by the supplied $options
.
The key of the combined entry is one of the duplicate keys:
- which one is chosen is There will be a single entry in the result
+ corresponding to a set of duplicate entries in the input.
+ The value of that entry will be taken from the first
+ of the duplicates. The position of that entry in the The key of the combined entry
+ will correspond to the key of one of the duplicates: it is
+ The position of the combined entry in the xs:dateTime
- values with different timezones.)
The entries that may appear in the $options
map are as follows:
$maps
contain entries with key values
- K1 and K2 where K1 and K2 are the
- combine
- option are mutually exclusive.
- "combine": fn(){error(xs:QName("err:FOJS0003"), ...)
- (the remaining arguments to "combine": fn($a, $b){ $a }
.
- "combine": fn($a, $b){ $b }
.
- "combine": fn($a, $b){ one-of($a, $b) }
- where one-of
chooses either $a
or $b
in
- an "combine": fn($a, $b){ $a, $b }
.
- $maps
contain entries with key values
- K1 and K2 where K1 and K2 are the
- duplicates
- option are mutually exclusive.
- fn(item()*, item()*) as item()*
.
- The function is called for any entry in an input map that has the
- An error is raised combine
and duplicates
- options are present.
An error is raised
By way of explanation, the function first reduces the sequence of input maps
- to a sequence of key-value pairs, retaining order of both the maps and of the
- entries within each map. It then combines key-value pairs having the
- $combine
function
- successively to pairs of duplicates. The position in the use-last
is used: the value of the resulting
- entry corresponds to the last entry with a given key, but the position of the entry
- in the result map corresponds to the position of the first entry with that key.
-
The use of "duplicates": "use-any"
, but it is not the only conformant
- implementation and is not intended to be a realistic implementation. The purpose of this
- option is to allow the implementation to use whatever strategy is most efficient; for example,
- if the input maps are processed in parallel, then specifying "duplicates": "use-any"
- means that the implementation does not need to keep track of the original order of the sequence of input
- maps.
If the input is an empty sequence, the result is an empty map.
If the input is a sequence of length one, the result map is
-
There is no requirement that
the supplied input maps should have the same or compatible
types. The type of a map (for example map(xs:integer, xs:string)
) is
descriptive of the entries it currently contains, but is not a constraint on how the map
may be combined with other maps.
The XSLT 3.0 recommendation included a specification of this function that incorrectly used
+ the option value {'duplicates':'unspecified'}
in place of
+ {'duplicates':'use-any'}
. XSLT implementations wishing to
+ preserve backwards compatibility
For consistency with the new functions combine
option as an alternative
- to the existing duplicates
option.
duplicates
option.
The function $input
argument.
The $options
argument can be used to control
the way in which duplicate keys are handled.
The
The entries that may appear in the $options
map are as follows:
fn($a, $b){ $a }
.
+ The effect is that the first of the duplicates is chosen.
+ fn($a, $b){ $b }
.
+ The effect is that the last of the duplicates is chosen.
+ fn($a, $b){ one-of($a, $b) }
+ where one-of
chooses either $a
or $b
in
+ an fn($a, $b){ $a, $b }
+ (or equivalently, the function op(",")
).
+ The effect is that the result contains the fn(item()*, item()*) as item()*
.
+ The function is called for any entry in the input sequence that has the
+ X => F(Y) => F(Z)
.
+ An error is raised $options
indicates that duplicates are to be rejected, and a duplicate key is encountered.
The function can be made to fail with a dynamic error in the event that
- duplicate keys are present in the input sequence by supplying a $combine
- function that invokes the
In the formal equivalent shown above:
+The call on error()
is indicative; the implementation
+ is free to raise the error in its own way.
The function $one-of($a, $b)
is intended to
+ illustrate that either $a
or $b
is returned,
+ at the discretion of the implementation. A function body is provided
+ for completeness, but it is not intended as a realistic implementation.
If the input is an empty sequence, the result is an empty map.
There is no requirement that the supplied key-value pairs should have the same or compatible
types. The type of a map (for example map(xs:integer, xs:string)
) is
descriptive of the entries it currently contains, but is not a constraint on how the map
may be combined with other maps.
When duplicate keys are encountered, the effect is that:
+In the
The key of the combined entry
+ will correspond to the key of one of the duplicates: it is
+ xs:dateTime
values in different timezones.)
$week
, supplemented with an additional
- entry.$week
, supplemented
+ with an additional entry.
$week
, with one entry replaced by a
new entry. Both input maps contain an entry with the key 6
; the
- supplied $combine
function ensures that the one used in the result
+ supplied $duplicates
option ensures that the one used in the result
is the one that comes last in the input sequence.The function $map
,
- with the exception of any entry whose key is the $key
, together with a new
- entry whose key is $key
and whose associated value is $value
.
If $map
contains an entry whose key is the $key
, the function returns
+ a map in which that entry is replaced (at the same relative position)
+ with a new entry whose value is $value
. It is
+ $key
.
+ All other entries in the map are unchanged, and retain their relative order.
The $map
contains an entry whose key is $key
,
- then the new value replaces the old value and the position of the entry is not changed;
- otherwise, the new entry is added after all existing entries.
Otherwise, when $map
contains no such entry, the function
+ returns a map containing all entries from the supplied $map
+ (retaining their relative position) followed by a new entry whose key
+ is $key
and whose associated value is $value
.
It is possible to force the new entry to go at the end of the sequence by calling
map:remove
before calling map:put
.
It can happen that the supplied $key
is the $map
, but nevertheless
+ differs from the existing key in some way:
+ for example, it might have a different type annotation, or it might be an xs:dateTime
+ value in a different timezone. In this situation it is
+ $key
or the existing key.
Enhanced to allow for ordered maps.
Enhanced to allow for ordered maps.
+It is no longer guaranteed that the new key replaces the existing key.
+It can happen that the supplied $key
is the $map
, but nevertheless
+ differs from the existing key in some way:
+ for example, it might have a different type annotation, or it might be an xs:dateTime
+ value in a different timezone. In this situation the key that appears in the result map
+ is always the supplied $key
, not the existing key.
If the key is not already present in the target map, the processor adds a new key-value pair to the map, with that key and that value.
If the key is already present, the processor calls the combine
- function in the $options
argument to combine the existing value for the key with the new value,
- and replaces the entry with this combined value.
The key of the combined entry is taken from one of the duplicate entries:
- it is If the key is already present, the processor combines the new value for the key
+ with the existing value as determined by the
+ and By default, when two duplicate entries occur: A single combined entry will be present in the result. This entry will contain the
+ The position of the combined entry in the
+ The key of the combined entry
+ will correspond to the key of one of the duplicates: it is
+ The position of the combined entry in the duplicates
option.xs:dateTime
values with different timezones.)
- xs:dateTime
values in different timezones.)
The $options
argument can be used to control the
+ way in which duplicate keys are handled. The allowed options, and their
+ meanings, are the same as for the
The $options
argument can be used to control the
- and the way in which duplicate keys are handled.
- The
The entries that may appear in the $options
map are as follows:
An error is raised $options
indicates that duplicates are to be rejected, and a duplicate key is encountered.
An error is raised $options
includes an entry whose key is defined
+ in this specification, and whose value is not a permitted value for that key.
The default function for both $keys
and $value
is the identity function.
Although it is permitted to default both, this serves little purpose: usually at least one of these arguments
will be supplied.
The default action for combining entries with duplicate keys is to perform a
- duplicates: combine
option on
fn($a, $b) { $a }
Use the first value and discard the remainder
fn($a, $b) { $b }
Use the last value and discard the remainder
fn:concat(?, ",", ?)
Form the string-concatenation of the values, comma-separated
fn:op('+')
Compute the sum of the values
The $input
from which they were derived. In the
- event that two entries have duplicate keys, the position of the combined entry
- in the result reflects the position of the first input item with that key.
The following expression creates a map whose keys are employee @location
values, and whose
corresponding values represent the number of employees at each distinct location. Any employees that
lack an @location
attribute will be excluded from the result.
The following expression creates a map whose keys are employee @location
values, and whose
diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml
index 40e591837..6a86b7cf9 100644
--- a/specifications/xpath-functions-40/src/xpath-functions.xml
+++ b/specifications/xpath-functions-40/src/xpath-functions.xml
@@ -771,8 +771,7 @@ Michael Sperberg-McQueen (1954–2024).
The type of the options parameter in the function signature is always
given as map(*)
.
Although option names are described above as strings, the actual key may be
- any value that compares equal to the required string (using the eq
operator
- with Unicode codepoint collation; or equivalently, the fn:atomic-equal
relation).
+ any value that is the xs:untypedAtomic
or xs:anyURI
are equally acceptable.
This means that the implementation of the function can check for the @@ -805,6 +804,7 @@ Michael Sperberg-McQueen (1954–2024).
A dynamic error occurs if the supplied value after conversion is not one of the permitted values for the option in question: the error codes for this error are defined in the specification of each function. +It is the responsibility of each function implementation to invoke this conversion; it does not happen automatically as a consequence of the function-calling rules.
Raised when the digits in the string supplied to
Raised if an inconsistent set of options is supplied
in an
Raised by regular expression functions such as xs:anyURI
or (when XPath 1.0 compatibility
mode is in force) an instance of xs:boolean
or xs:duration
.
When
For compatibility issues regarding earlier versions, see the 3.1 version of this specification.
diff --git a/specifications/xslt-40/src/element-catalog.xml b/specifications/xslt-40/src/element-catalog.xml index cd6c7af27..6b87e08a6 100644 --- a/specifications/xslt-40/src/element-catalog.xml +++ b/specifications/xslt-40/src/element-catalog.xml @@ -1702,7 +1702,7 @@The following example modifies a supplied map $input
by wrapping
each of the values in an array:
This could also be written:
xsl:map/@on-duplicates
is available,
+ A new attribute xsl:map/@duplicates
is available,
allowing control over how duplicate keys are handled by the This section describes what happens when two or more maps in the input sequence of
within an fn:atomic-equal(K, L)
returns true
.
fn:atomic-equal(K, L)
returns true
.
In the absence of the In the absence of the on-duplicates
attribute,
+ duplicates
attribute,
a
The result of evaluating the on-duplicates
attribute, if present,
The result of evaluating the duplicates
attribute, if present, "use-first"
, "use-last"
,
+ "use-any"
, "combine"
, or "reject"
,
+ or a function with arity 2. These values correspond to the permitted
+ values of the duplicates
option of the
+
The result of the $maps
+ is the input sequence to $duplicates
+ is the duplicates
+ attribute, then the result of the instruction is the result of the function
+ call map:of-pairs(map:pairs($maps), { "duplicates": $duplicates })
.
Thus, if the values are all singleton items (which is not necessarily the case), and if the sequence
of values is S, then the final result is fold-left(tail(S), head(S), F)
.
For example, the following table shows some useful callback functions that might be supplied, - and explains their effect:
+ --> +The following table shows some possible values
+ of the duplicates
attribute, and explains their effect:
fn($a, $b) { $a } |
+ duplicates="use-first" |
The first of the duplicate values is used. | |
fn($a, $b) { $b } |
+ duplicates="use-last" |
The last of the duplicate values is used. | |
fn($a, $b) { $a, $b } |
- The sequence-concatenation of the duplicate values is used.
- on-duplicates="op(',')" . |
+ duplicates="combine" |
+ The on-duplicates="op(',')" . |
fn($a, $b) { max(($a, $b)) } |
+ duplicates="fn($a, $b) { max(($a, $b)) }" |
The highest of the duplicate values is used. | |
fn($a, $b) { min(($a, $b)) } |
+ duplicates="fn($a, $b) { min(($a, $b)) }" |
The lowest of the duplicate values is used. | |
fn($a, $b) { string-join(($a, $b), ', ') } |
+ duplicates="concat(?, ', ', ?) }" |
The comma-separated string concatenation of the duplicate values is used. | |
fn($a, $b) { $a + $b } |
- The sum of the duplicate values is used.
- This could also be expressed as on-duplicates="op('+')"
+ | ||
duplicates="op('+')" |
+ The sum of the duplicate values is used. | +||
duplicates="fn($a, $b) { subsequence(($a, $b), 1, 4) }" |
+ The first four of the duplicates are retained; any further duplicates + are discarded. | ||
fn($a, $b) { error() } |
- Duplicates are rejected as an error (this is the default in the absence of a - callback function). | +duplicates="fn($a, $b) { distinct-values(($a, $b)) }" |
+ When multiple entries have the same key, the corresponding values + are retained only if they are distinct from other values having the + same key. + |
The logic is:
Specifying the effect by reference to
The position of the merged entry in the result corresponds + to the position of the first of the duplicate keys in the input.
The key used for the merged entry in the result corresponds
+ to one of the duplicate keys in the input: it is
+ xs:dateTime
+ values in different timezones.