XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (72 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
9.16Mb size Format: txt, pdf, ePub

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:

  • Firstly, all the built-in atomic types defined in the XML Schema specification become available. These include the additional primitive type
    xs:NOTATION
    , and types derived from
    xs:string
    and
    xs:integer
    , such as
    xs:normalizedString
    and
    xs:nonNegativeInteger
    . A full list of these types, with explanations of their meanings, is given in Chapter 5.
  • Secondly, user-defined types can be imported from an XML Schema definition.

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

declaration, which might take the form:

                   schema-location=“acme.xsd”/>

The

declaration is described in more detail later in this chapter (see page 180). You can import any number of schema documents into a stylesheet, provided that the namespaces do not clash. If you want to refer to types defined in a schema by name, then you must import that schema into the stylesheet using an

declaration. However, you don't need to import a schema simply because you are using it to validate source or result documents.

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:

Other books

Last Man Out by James E. Parker, Jr.
Planet Lolita by Charles Foran
Made with Love by Tricia Goyer
Helsreach by Aaron Dembski-Bowden
The Tomb of Zeus by Barbara Cleverly
The Saga of Colm the Slave by Mike Culpepper
Ruin: Revelations by Bane, Lucian
Going Away Shoes by Jill McCorkle
The Vanishing by Jana DeLeon