Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The shaded boxes show abstract types, and the clear boxes represent concrete types. The difference is that a value can never belong to an abstract type unless it also belongs to one of the concrete subtypes of that type.
The most general type here is
item()
, which allows any kind of item. The two kinds of items are nodes, shown on the left-hand branch of the type hierarchy, and atomic values, shown on the right-hand branch.
In a sequence type descriptor, any of the item types listed in
Figure 4-1
may be followed by one of the occurrence indicators
*
,
+
, or
?
. The occurrence indicator defines how many items (of the given item type) may appear in the value. They have the following meanings:
Occurrence indicator | Meaning |
* | Zero or more occurrences allowed |
+ | One or more occurrences allowed |
? | Zero or one occurrence allowed |
If there is no occurrence indicator, then the value must contain exactly one item of the specified type.
In a schema-aware processor, this type hierarchy is extended in the following two ways:
To make user-defined types available for use in type declarations in a stylesheet, the schema must first be imported into the stylesheet. This can be done with an
schema-location=“acme.xsd”/>
The
The types defined in a schema are either complex types or simple types, and simple types in turn divide into three varieties: union types, list types, and atomic types.
When atomic types are imported from a schema, they can be used in a stylesheet in just the same way as the built-in atomic types. For example, if the schema defines an atomic type
mf:part-number
as a subtype of
xs:string
constrained to conform to a particular pattern, then in the stylesheet you can declare a variable:
which informs the system that the value of the
$part
variable will always be a part number. The expression in the
select
attribute must return a valid part number according to these rules, or the transformation will fail.
Note that to conform to this type, it's not enough to supply a string that matches the schema-defined pattern. The value must actually be labeled as an
mf:part-number
. To achieve this, you typically have to convert the value to the required type using a constructor function. For example, you could write:
select=“mf:part-number(‘BFG94623’)”/>
Atomic values can exist independently of any node in a document, which is why you can use an atomic type directly as the type of a value. In contrast, instances of complex types, union types, and list types can exist only as the content of a node in a document. This means that the names of these types can't be used directly in an
as
attribute defining the type of a variable or parameter. You can use them, however, to qualify a type that describes a node. Examples of such sequence type descriptors are shown in the table below: