From ad643e7dd6939746122a1224c444d705eedd5b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gr=C3=BCn?= Date: Sun, 17 Dec 2023 15:03:44 +0100 Subject: [PATCH 1/2] fn:compare: Support for arbitrary atomic types. #893 --- .../src/function-catalog.xml | 172 ++++++++++++++++-- .../src/xpath-functions.xml | 32 ++-- 2 files changed, 175 insertions(+), 29 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 8fb1f7cf6..925d23369 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -3624,8 +3624,8 @@ return if (starts-with($preprocessed-value, "-")) then -$abs else +$abs]]> - - + + @@ -3640,22 +3640,133 @@ return if (starts-with($preprocessed-value, "-")) then -$abs else +$abs]]> focus-independent -

Returns -1, 0, or 1, - depending on whether $value1 collates before, - equal to, or after $value2 according to the rules of a selected - collation.

+

Returns -1, 0, or 1, depending on whether + the first value is less than, equal to, or greater than the second value.

-

Returns -1, 0, or 1, - depending on whether $value1 is - respectively less than, equal to, or greater than $value2, - according to the rules of the collation that is used.

-

The collation used by this function is determined according to the rules in .

+

Compares two atomic values $value1 and $value2 for order, and + returns the integer value -1, 0, or 1, + depending on whether $value1 is less than, equal to, or greater than + $value2, respectively.

If either $value1 or $value2 is the empty sequence, the function returns the empty sequence.

-

This function, when used with the default collation, defines the semantics of the eq, ne, - gt, lt, le and ge operators on xs:string values.

+

Otherwise, the result is determined as follows:

+ + +

If $value1 is an instance of xs:string, + xs:anyURI or xs:untypedAtomic, and if + $value2 is an instance of xs:string, xs:anyURI + or xs:untypedAtomic, the values are compared as strings, and the + result reflects the order according to the rules of the collation that is used.

+

The collation is determined according to the rules in + .

+

When used with the default collation, + the function defines the semantics of the eq, ne, + gt, lt, le and ge + operators on xs:string values.

+
+ +

If both $value1 and $value2 are instances of + xs:numeric, the result of + fn:numeric-compare($value1, $value2) is returned.

+
+ +

If both $value1 and $value2 are instances of + xs:boolean, then:

+ +

-1 is returned if + op:boolean-less-than($value1, $value2) returns true.

+
+

0 is returned if + op:boolean-equal($value1, $value2) returns true.

+
+

1 is returned otherwise.

+
+
+ +

If $value1 is an instance of xs:hexBinary or + xs:base64Binary, and if $value2 is an instance of + xs:hexBinary or xs:base64Binary, then:

+ +

-1 is returned if + op:binary-less-than($value1, $value2) returns true.

+
+

0 is returned if + op:binary-equal($value1, $value2) returns true.

+
+

1 is returned otherwise.

+
+
+ +

If both $value1 and $value2 are instances of + xs:date, then:

+ +

-1 is returned if + op:date-less-than($value1, $value2) returns true.

+
+

0 is returned if + op:date-equal($value1, $value2) returns true.

+
+

1 is returned otherwise.

+
+
+ +

If both $value1 and $value2 are instances of + xs:time, then:

+ +

-1 is returned if + op:time-less-than($value1, $value2) returns true.

+
+

0 is returned if + op:time-equal($value1, $value2) returns true.

+
+

1 is returned otherwise.

+
+
+ +

If both $value1 and $value2 are instances of + xs:dateTime, then:

+ +

-1 is returned if + op:dateTime-less-than($value1, $value2) returns true.

+
+

0 is returned if + op:dateTime-equal($value1, $value2) returns true.

+
+

1 is returned otherwise.

+
+
+ +

If both $value1 and $value2 are instances of + xs:dayTimeDuration, then:

+ +

-1 is returned if + op:dayTimeDuration-less-than($value1, $value2) returns true.

+
+

0 is returned if + op:duration-equal($value1, $value2) returns true.

+
+

1 is returned otherwise.

+
+
+ +

If both $value1 and $value2 are instances of + xs:yearMonthDuration, then:

+ +

-1 is returned if + op:yearMonthDuration-less-than($value1, $value2) returns true.

+
+

0 is returned if + op:duration-equal($value1, $value2) returns true.

+
+

1 is returned otherwise.

+
+
+ +

For any other combination of types, a type error + is raised.

+
+
@@ -3698,7 +3809,40 @@ return if (starts-with($preprocessed-value, "-")) then -$abs else +$abs]]> base characters, such as the final n. + + + compare(9, 10) + -1 + + + + + compare(false(), true()) + -1 + + + + + compare(true(), parse-xml-fragment('1')) + 0 + + + + + compare(xs:time('23:59:59'), xs:time('00:00:00')) + 1 + + + + + compare(xs:date('2001-01-01'), xs:untypedAtomic('2001-01-01')) + 0 + + + + Changed in 4.0: Enhanced to accept types other than strings. +
diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml index fce1b0831..d38920e9f 100644 --- a/specifications/xpath-functions-40/src/xpath-functions.xml +++ b/specifications/xpath-functions-40/src/xpath-functions.xml @@ -2705,9 +2705,6 @@ string conversion of the number as obtained above, and the appropriate suff may also cause an error if they cannot be resolved against the relevant base URI.

- - - @@ -5450,15 +5447,12 @@ correctly in all browsers, depending on the system configuration.

--> - - - - - - - - - + + + + + + @@ -5468,9 +5462,15 @@ correctly in all browsers, depending on the system configuration.

--> - - - + + + + + + + + + Functions that test the cardinality of sequences @@ -11973,6 +11973,8 @@ declare function eg:distinct-nodes-stable ($arg as node()*) as node()* { argument syntax in function calls.

The fn:deep-equal function has an options argument giving detailed control over how two values are compared.

+

The fn:compare function has been enhanced to accept types + other than strings.

The fn:format-integer function can produce output in non-decimal radices, for example binary and hexadecimal.

The fn:json-doc function accepts additional options.

From f33735eceff6df8e80e96d8eead82736c933a70b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gr=C3=BCn?= Date: Wed, 3 Jan 2024 17:33:39 +0100 Subject: [PATCH 2/2] Examples revised --- .../xpath-functions-40/src/function-catalog.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 925d23369..aaedad30f 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -3815,6 +3815,12 @@ return if (starts-with($preprocessed-value, "-")) then -$abs else +$abs]]> -1 + + + compare(123, 123.0) + 0 + + compare(false(), true()) @@ -3823,7 +3829,7 @@ return if (starts-with($preprocessed-value, "-")) then -$abs else +$abs]]> - compare(true(), parse-xml-fragment('1')) + text'))]]> 0 @@ -3835,7 +3841,7 @@ return if (starts-with($preprocessed-value, "-")) then -$abs else +$abs]]> - compare(xs:date('2001-01-01'), xs:untypedAtomic('2001-01-01')) + compare(xs:date('2001-01-01'), xs:date('2001-01-01')) 0