Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Examples
Let's try to put these different forms into context by seeing how they can be used with a real schema. I'll use as my example the schema for XSLT 2.0 stylesheets, which is published in an appendix of the XSLT 2.0 specification at
http://www.w3.org/TR/xslt20
. This example is therefore relevant if you are using XPath expressions to access an XSLT 2.0 stylesheet (which is not as esoteric a requirement as you might think), and it also assumes that the XSLT 2.0 stylesheet has been validated against this schema.
The schema starts with a couple of complex type definitions like this:
Every element in the XSLT namespace has a type that is derived ultimately from
generic-element-type
, and most of them are also derived from
versioned-element-type
. If we want to use a sequence type descriptor (perhaps to declare a variable or a function argument in XSLT) that accepts any element in the XSLT namespace that is valid against this schema, we could declare this as:
If we wanted to exclude those elements that don't allow a
version
attribute (there is only one,
version
attribute, but defines it differently), then we could write the sequence type descriptor as:
The schema goes on to provide two abstract element declarations, like this:
These are declared as abstract because you can't actually include an element in a stylesheet whose name is
sequence constructor
. A sequence constructor is a sequence of elements in the stylesheet that may include variable definitions, instructions, and literal result elements, and its format is defined in the schema like this:
Elements that allow a sequence constructor as their content, such as
minOccurs=“0” maxOccurs=“unbounded”/>
The abstract element
schema-element(xsl:instruction)
to match any element that is an XSLT instruction: that is, an element that is in the substitution group of
The schema for XSLT 2.0 stylesheets does not include any global attribute declarations, so you will never see a sequence type descriptor of the form
schema-attribute(xsl:xxxx)
. This is fairly typical: attributes are most commonly declared either as part of the element declaration to which they belong, or in constructs such as
xs:attributeGroup
. For example, the set of
xsl:
prefixed attributes that can appear on literal result elements is defined in the schema for XSLT 2.0 in an attribute group:
type=“xsl:prefixes”/>
type=“xsl:prefixes”/>
type=“xs:anyURI”/>
type=“xsl:QNames” default=“”/>
type=“xs:decimal”/>
type=“xsl:QName”/>
type=“xsl:validation-type”/>