diff --git a/specifications/xquery-40/src/expressions.xml b/specifications/xquery-40/src/expressions.xml index 2451a8fe1..f6c316d52 100644 --- a/specifications/xquery-40/src/expressions.xml +++ b/specifications/xquery-40/src/expressions.xml @@ -5681,8 +5681,10 @@ name.
The equivalent in XSLT is:
-The visibility
attribute. The value is one of private
,
+ visibility
attribute. The permitted value is some subset of private
,
public
, abstract
, or final
(never
hidden
). In the case of
an
The visibility of a
named template, function, variable, attribute set, mode,
-
Except where recursive types are involved, a named item type +
A named item type
(declared in an visibility="final"
.
Two named record types are compared by name, not by content. This is
+ because named record types may potentially be recursive, so the name
+ cannot always be expanded to an expressible record type designator.
+ By implication, the named record type must itself be declared or exposed
+ with visibility="public"
.
Modes are not overridable, so the
Modes, named item types, and named record type are not overridable,
+ so
version="1.0"
otherwise.
version="1.0"
otherwise.
contains entries with keys "first"
and "last"
.
type(complex)
matches any value that is an instance of the item type declared in an
type(complex)
matches any value that is an instance of the item type
+ declared in an "complex"
type(complex)[?i eq 0]
matches any value that is an instance of the item type declared in an
type(complex)[?i eq 0]
matches any value that is an instance of the
+ item type declared in an "complex"
and that is a map with an entry having key i
and value zero.
version="1.0"
otherwise.
- XSLT 4.0 introduces two new and closely-related constructs allowing item + types to be given names, and to be referred to by name anywhere that item types + are used, for example in function declarations and variable declarations.
- +The
An
The following example declares a named item type for complex numbers, and uses it in a variable - declaration and a function declaration.
-The
Named record types can be recursive, allowing definitions of + recursive data structures such as lists and trees.
Declaring a named record type automatically establishes + a constructor function for records of that type; the constructor + function has the same name as the record type itself.
An
The following example declares a named item type for colors, and uses it in three variable + declarations and a function declaration.
+The following example declares a named choice type for the two binary
+ types xs:hexBinary
and xs:base64Binary
+ and uses it in a function declaration that compares two such values
+ for equality.
Using named item types makes the stylesheet more readable, and improves potential for change: a change
+ to the set of colors allowed by the type my:color
is less likely to affect users of a function
+ library. However, named item types do not provide true encapsulation or information hiding; users of the
+ function library can still treat enumeration values as simple strings if they wish.
The ItemType
to appear.
The scope of a named item type is the visibility="public"
then it also becomes available for use in using
+ packages. (Since there is no mechanism for the using package to override the definition,
+ public
effectively means final
.)
A named item type is essentially an abbreviation for the item type designator appearing in the
+ as
attribute, and the semantics can be defined in terms of textual replacement
+ of the name by its definition. In consequence, named item types cannot be recursive, since
+ this would make the textual expansion non-terminating.
The name of the item type is the expanded name formed by resolving the name
attribute.
+ A lexical QName with no prefix is treated as being in the
+
If two
It is a
It is a as
attribute a reference to N,
+ or to an item type that references N directly or indirectly.
It is permissible to use a private named item type in the declaration of a public + variable, function, or template. A package that uses (or overrides) such a component + will not be able to use the type name, but it can use the underlying type definition, + or provide its own declaration of the relevant item type, using the same name or + a different name.
+An
The following example declares a named record type for complex numbers, + and uses it in a variable + declaration and a function declaration.
+Note how the item type declaration has implicitly declared a constructor function
- cx:complex
that can be used to create instances of the item type;
- details of this mechanism are at
Using named item types makes the stylesheet more readable, and improves potential for change: a change - to the way complex numbers are implemented in this example is less likely to affect users of the function - library. However, named item types do not provide true encapsulation or information hiding; users of the - function library can still treat complex numbers as raw maps if they wish.
-The ItemType
to appear.
The scope of a named item type is the visibility="final"
then it also becomes available for use in using
- packages. Named item types cannot be overridden in a using package, so the only permitted values for
- visibility
are private
and final
.
The name of the item type is the expanded name formed by resolving the name
attribute.
- A lexical QName with no prefix is treated as a no-namespace name.
If two
It is a
An item type declaration may refer directly or indirectly to itself if
- it satisfies the conditions defined in
It is a as
attribute a reference to N,
- or to an item type that references N directly or indirectly, unless it satisfies
- the conditions defined in
TODO: add named item types to xsl:accept and xsl:expose. Clarify that when a function or variable - is exported to a different package, its declared type/signature uses the expanded form of any named - item type; there is no requirement for the using package to know the named item types. But it becomes - easier to use the exposed variables and functions if the names of the types are exposed too.
+]]>Note how the record type declaration has implicitly declared a constructor function
+ cx:complex
that can be used to create instances of the item type.
It is a
It is a default
+ attribute unless it specifies required="no"
.
An
In the same way as ItemType
can appear,
+ for example in the declarations of functions and variables. Unlike
+ types declared in
An
Because of its dual role, the name of an
Considered as an item type, the <xsl:namespace-alias stylesheet-prefix="t"
+ result-prefix="xsl"/>
:
This generated
For example, the declaration:
+ +produces the equivalent item type declaration:
+ +Considered as a function declaration, an <xsl:namespace-alias stylesheet-prefix="t"
+ result-prefix="xsl"/>
:
For example, the declaration:
+ +produces the equivalent function declaration:
+ +No entry is generated in the constructed map for a field that + is declared as optional with no default. So the declaration:
+ +produces the equivalent function declaration:
+ +If the record type is extensible, the generated function
+ includes an optional options
parameter So the declaration:
produces the equivalent function declaration:
+ +This generated
The generated public
+ then it can also be overridden using
The scope of a named record type is the visibility="public"
then it also becomes available for use in using
+ packages.
The name of the record type is the expanded name formed by resolving the name
attribute.
+ Because function names are always in a namespace, the name must be prefixed.
If two
It is a
A record type declaration may refer directly or indirectly to itself if
+ it satisfies the conditions defined in
It is a as
attribute a reference to N,
+ or to an item type that references N directly or indirectly, unless it satisfies
+ the conditions defined in
A named record type with visibility private
may be used in the definition of a
+ component (such as a variable, a function, a template, or another named record
+ type) that is itself public. Another package may reference such a component
+ even though it cannot reference the types used in its definition. The fact that the
+ record type is private, however, means that it is impossible to
+ override a variable or function that references the record type.
This example illustrates the definition of a recursive record type.
+ The record type represents a node of a binary tree containing a payload value
+ in each node, together with optional references to left and right subtrees.
+ As well as the data fields, the record type defines a depth
function
+ that returns the maximum depth of the tree, by making recursive calls on its
+ subtrees.
The =?>
operator is described in
+
The following code builds a simple tree and calculates its depth:
+ +Returning the result 3.
+version="1.0"
otherwise.
}
]
The following template rules are used. The setting expand-text="yes"
is assumed:
version="1.0"
otherwise.