From 8680a312d6616724e5852936c1262689fe793e72 Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Tue, 12 Nov 2024 12:57:09 +0000 Subject: [PATCH 1/4] Replace node-kind() with new type-of() function --- .../src/function-catalog.xml | 143 ++++++++++++++++++ .../src/xpath-functions.xml | 7 +- 2 files changed, 147 insertions(+), 3 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 45f2e37ab..c780bdc88 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -615,6 +615,149 @@ $node ! ( + + + + + + + + deterministic + context-dependent + focus-dependent + + + deterministic + context-independent + focus-independent + + +

Returns information about the type of a value, as a string.

+
+ +

If the argument is omitted, it defaults to the context value (.).

+

If $item is the empty sequence, the function returns the string "empty-sequence()".

+

Otherwise, the function returns a string, whose lexical form will always match + the grammar of SequenceType, representing a sequence type that matches + $value. The returned string is the concatenation of:

+ +

A string representing the distinct item types that are present in $value, + formed as follows:

+ +

For each item in $value, construct a string representing its item type + as described below.

+

Eliminate duplicate strings from this list by applying the fn:distinct-values + function, forming a sequence of strings $ss.

+

If $ss contains only one string, use that string.

+

Otherwise, return the result of the expression `({fn:string-join($ss, "|")})`.

+
+
+

An occurrence indicator: absent if $value contains exactly one item, or + "+" if it contains more than one item.

+
+

The string representing the type of an individual item J is constructed as follows:

+ +

If J is a node, the result is one of the following + strings, determined by the node kind of the node (see ):

+

+ "document-node()" + "element()" + "attribute()" + "text()" + "processing-instruction()" + "comment()" + "namespace-node()" +

+
+ +

If J is an atomic item, the result is a string chosen as follows:

+ +

Let T be the type denoted by the type annotation of J.

+

If T is an anonymous type, set T to the base type of T, and + repeat until a type is reached that is not anonymous.

+

If the name of T is in the namespace http://www.w3.org/2001/XMLSchema, + return the string "xs:local" where local is the local part of the + name of T.

+

Otherwise, return the name of T in the form of a + URIQualifiedName (that is, "Q{uri}local", + or "Q{}local" if the name is in no namespace).

+
+
+

If J is a function item:

+ +

If J is an array, return "array(*)".

+

If J is a map, return "map(*)".

+

Otherwise, return "function(*)".

+
+
+
+
+ + +

If the $value argument is omitted and the context value is absent, the function raises + type error .

+ +
+ +

In general, an item matches more than one type, and there are cases where there is no single matching type that + is more specific than all the others. This is especially true with functions, maps, and arrays. This function therefore + selects one of the types that matches the item, which is not necessarily the most specific type.

+
+ + + +

One

+

Two

+ Three + +]]> +
+ + + type-of($e//*[@id = 'alpha']) + "element()" + + + type-of($e//*) + "element()+" + + + type-of($e//@id[. = 'gamma']) + "attribute()" + + + type-of($e//node()[.='3.14159']) + "processing-instruction()" + + + type-of($e//no-such-node) + "empty-sequence()" + + + type-of($e//doc/child::node()) + "(element()|processing-instruction())+" + + + type-of(1) + "xs:integer" + + + type-of(1 to 5) + "xs:integer+" + + + type-of((1, 1.2, 2)) + "(xs:integer|xs:decimal)+" + + +
+ +

New in 4.0

+
+
+ diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml index 73e77229c..965882645 100644 --- a/specifications/xpath-functions-40/src/xpath-functions.xml +++ b/specifications/xpath-functions-40/src/xpath-functions.xml @@ -1415,9 +1415,7 @@ This includes all the built-in datatypes defined in . - - - + @@ -9161,6 +9159,9 @@ return + + + From 473ff66f4248abe69526206a24e8cf5ebeea8a6e Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Tue, 12 Nov 2024 13:01:26 +0000 Subject: [PATCH 2/4] Drop type-of#0 --- .../xpath-functions-40/src/function-catalog.xml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index c780bdc88..490408afb 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -618,15 +618,10 @@ $node ! ( - + - - deterministic - context-dependent - focus-dependent - - + deterministic context-independent focus-independent @@ -635,8 +630,7 @@ $node ! (

Returns information about the type of a value, as a string.

-

If the argument is omitted, it defaults to the context value (.).

-

If $item is the empty sequence, the function returns the string "empty-sequence()".

+

If $value is the empty sequence, the function returns the string "empty-sequence()".

Otherwise, the function returns a string, whose lexical form will always match the grammar of SequenceType, representing a sequence type that matches $value. The returned string is the concatenation of:

@@ -754,7 +748,7 @@ $node ! ( -

New in 4.0

+

New in 4.0

From fa7998155c4b4b91656ea97061e1fc08a3930549 Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Tue, 12 Nov 2024 13:06:10 +0000 Subject: [PATCH 3/4] Editorial rephrasing --- specifications/xpath-functions-40/src/function-catalog.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 490408afb..a7fa79cf4 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -630,10 +630,11 @@ $node ! (

Returns information about the type of a value, as a string.

-

If $value is the empty sequence, the function returns the string "empty-sequence()".

-

Otherwise, the function returns a string, whose lexical form will always match +

The function returns a string, whose lexical form will always match the grammar of SequenceType, representing a sequence type that matches - $value. The returned string is the concatenation of:

+ $value.

+

If $value is the empty sequence, the function returns the string "empty-sequence()".

+

Otherwise, the returned string is the concatenation of:

A string representing the distinct item types that are present in $value, formed as follows:

From 4a96e0e482cb2de7e5e548caa498af620342b9bb Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Tue, 12 Nov 2024 14:43:10 +0000 Subject: [PATCH 4/4] Add notes on usage of type-of() --- .../xpath-functions-40/src/function-catalog.xml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index a7fa79cf4..178e0c5f7 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -699,6 +699,19 @@ $node ! (

In general, an item matches more than one type, and there are cases where there is no single matching type that is more specific than all the others. This is especially true with functions, maps, and arrays. This function therefore selects one of the types that matches the item, which is not necessarily the most specific type.

+ +

This function should not be used as a substitute for an instance of test. The precise type annotation + of the result of an expression is not always predictable, because processors are free to deliver a more specific type + than is mandated by the specification. For example, if $n is of type xs:positiveInteger, + then the result of abs($n) is guaranteed to be an instance of xs:integer, but an + implementation might reasonably return the supplied value unchanged: that is, a value whose actual type + annotation is xs:positiveInteger. Similarly the type annotation of the value returned by + position() might be xs:long rather than xs:integer.

+ +

Implementations should, however, refrain from exposing types that are purely internal. + For example, an implementation might have an optimized internal representation for strings consisting entirely + of ASCII characters, or for single-character strings; if this is the case then the type annotation returned by this function + should be a user-visible supertype such as xs:string.

@@ -22368,7 +22381,7 @@ declare function transitive-closure ( then the result of abs($n) is guaranteed to be an instance of xs:integer, but an implementation might reasonably return the supplied value unchanged: that is, a value whose actual type annotation is xs:positiveInteger. Similarly the type annotation of the value returned by - position() might have a type annotation of xs:long rather than xs:integer.

+ position() might be xs:long rather than xs:integer.

Implementations should, however, refrain from exposing types that are purely internal. For example, an implementation might have an optimized internal representation for strings consisting entirely