XML technologies / XSLT / Reference: XSLT 1.0 and 2.0 elements / document
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 6.)
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
The instruction xsl:document is used to validate a temporary document tree created during transformation.
Classification | Instruction |
Function group | Creating a temporary tree |
Introduction | XSLT 2.0 |
Position in the stylesheet and permitted contents:
The instruction xsl:document may occur in XSLT elements generating a temporary tree or a tree not serialised as a document.
It contains a sequence constructor generating a node sequence to serve as a document tree.
Attributes:
Standard attributes apply to xsl:document. Two optional element-specific attributes are validation and type.
type
Value | |
Usage | Optional |
Introduction | XSLT 2.0 |
Since the generated document node has no type itself, attribute type does not apply directly to it. The schema-type QName instead identifies the type of the tree’s principal node, its root element. A nonexistent declaration for that QName is a static error (ERR XTSE1520).
Root-element validation follows the usual element-node procedure (Note: a formal, rather theoretical description is available in XML Schema specification, part 1, section 3.3.4). If validation succeeds, meaning the validity property in the generated PSVI has value valid for the node, the supplied type is bound to the element. Otherwise stylesheet processing stops (ERR XTTE1540).
validation
Value | "strict" | "lax" | "preserve" | "strip" |
Usage | Optional |
Introduction | XSLT 2.0 |
The validation attribute controls whether and how the root element is validated. It has no direct default; if absent, the enclosing stylesheet element’s default-validation attribute on xsl:stylesheet or xsl:transform supplies the value. If default-validation is absent there too, its default strip applies.
The four explicit values of validation are strict, lax, preserve and strip, with these effects:
validation = "strict"
Valuestrictenforces strict schema validation of the root element. The root and its allowed content must be declared in an available schema, located through the usual XML Schema methods. This can be implicit through the namespace or explicit through an addedxsi:schemaLocationattribute on its elements. The resultingvalidityproperty in the PSVI must have valuevalid; the root then receives the type binding, while existing bindings in the tree remain. A property value ofinvalidornotKnowncauses the transformation to fail with a type error. A type error also occurs unless the document node contains exactly one element, the root, and otherwise only comments and PIs.
validation = "lax"
Valuelaxrequires root validation against an available schema, but the absence of a schema or root declaration is not an error. The node’svalidityproperty may therefore bevalidornotKnown. In the latter case, the unvalidated root receives typexs:untyped. Existing bindings in the tree remain. If thevalidityproperty isinvalid, transformation fails with a type error. A type error also occurs unless the document node contains exactly one root element and otherwise only comments and PIs.
validation = "preserve"
Valuepreservepreserves explicitly established bindings of elements and attributes to data types. Explicit binding may come from attributevalidationonxsl:elementorxsl:copy-of. Other element and attribute nodes lose any type binding and receivexs:anyTypefor elements andxs:anySimpleTypefor attributes, as withvalidation="none".
validation = "strip"
Valuestripremoves all type bindings in the document tree, assigningxs:untypedto every element andxs:anySimpleTypeto every attribute.
Purpose:
The instruction xsl:document creates a document node in the same way as xsl:result-document. Its sequence constructor supplies the content. The node can be added directly to the result sequence or stored in a variable as a temporary tree.
Its main purpose is additionally to validate that document as it is created, through either attribute validation or type.
This validates a temporary tree immediately when created in a variable. Otherwise validation waits until the variable is referenced and the tree copied with xsl:copy, which, unlike xsl:variable itself, supports validation:
<xsl:variable name="temp-baum">
<xsl:document validation="strict">
<!-- Erzeugung des Baums -->
</xsl:document>
</xsl:variable>
The aim is to validate as early as possible so any error occurs when the tree is created.
Element definition:
XSLT 1.0:
Element unavailable in XSLT 1.0.
XSLT 2.0:
<!-- Category: instruction -->
<xsl:document
validation? = "strict" | "lax" | "preserve" | "strip"
type? = sequence-type >
<!-- Content: sequence-constructor -->
</xsl:document>
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn