Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Construct | Meaning |
element(*, mf:invoice) | An element node validated against the complex type mf:invoice defined in an imported schema |
attribute(*, xs:NMTOKENS) | An attribute validated against the built-in schema list type xs:NMTOKENS |
document-node(element(*, mf:invoice)) | A document node representing a well-formed XML document whose outermost element has been validated against the complex type mf:invoice defined in an imported schema |
Often the structure of an element is defined in the schema not by creating an explicitly named
To allow for the fact that many of the types defined in a typical schema are anonymous, there is another form of the
element()
test that is used to refer to elements conforming to this named element declaration. If you write:
then you are saying that the value of the parameter must be an element that has been validated against the element declaration
xsl:apply-imports
in this schema. The name of the element passed as the parameter must either be
xsl:apply-imports
, or must match an element defined in the schema to be a member of the substitution group of
xsl:apply-imports
.
You can similarly refer to top-level attribute declarations in the schema using the syntax
schema-attribute(nnn)
, though this form is not seen very often because it is unusual to find top-level attribute declarations in a schema.
Sequence type descriptors can also be used within XPath expressions. The expressions that use them are described in Chapter 11, which also defines the syntax and semantics in much greater detail than defined here. The operators that use sequence type descriptors are as follows:
Validating the Source Document
Validation is the process of taking a raw XML document and processing it using an XML Schema. The most obvious output of this process is a success or failure rating: the document is either valid or invalid against the schema. But this is not the only output. Validation also annotates the document, marking each element and attribute node with a label indicating its type. For example, if validation checks that a
us-postal-address
type in the schema, then this element will be annotated as having the type
us-postal-address
. There are various ways the stylesheet can then use this information: