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

QName

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 valida­tion 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"
    Value strict enforces 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 added xsi:schemaLocation attribute on its elements. The resulting validity property in the PSVI must have value valid; the root then receives the type binding, while existing bindings in the tree remain. A property value of invalid or notKnown causes 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"
    Value lax requires root validation against an available schema, but the absence of a schema or root declaration is not an error. The node’s validity property may therefore be valid or notKnown. In the latter case, the unvalidated root receives type xs:untyped. Existing bindings in the tree remain. If the validity property is invalid, 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"
    Value preserve preserves explicitly established bindings of elements and attributes to data types. Explicit binding may come from attribute validation on xsl:element or xsl:copy-of. Other element and attribute nodes lose any type binding and receive xs:anyType for elements and xs:anySimpleType for attributes, as with valida­tion="none".

  • validation = "strip"
    Value strip removes all type bindings in the document tree, assigning xs:untyped to every element and xs:anySimpleType to 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>

   

  

back to top