XML technologies / XSLT / Reference: XSLT 1.0 and 2.0 elements / Formal classification of XSLT elements

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 6.)

XSLT 1.0’s 35 elements and XSLT 2.0’s 49 elements fall into four formal groups according to their permitted hierarchical position in a stylesheet:

Root elements

Two XSLT elements can serve as a stylesheet document’s root: xsl:stylesheet and xsl:transform. They are synonymous and have identical effects. Their different names are historical, dating from before XSL separated presentation, now XSL-FO, from transformation, now XSLT.

Although xsl:transform would be the more natural name, xsl:stylesheet became the customary root element. Besides setting the XSLT version with the ver­sion attribute, the root element declares the namespace for the XSLT instruction set used.

The two root elements xsl:stylesheet and xsl:transform are also functionally called stylesheet elements.

Top-level elements

Top-level elements can occur as immediate children of the root, or are allowed only there. The most important is arguably xsl:template, which defines template rules.

XSLT also calls top-level elements declarations.

Top-level element order is unrestricted and usually irrelevant. In principle they may occur in any number and order. The sole exception is xsl:import, which, if used, must always appear first among the root’s children, any number of times.

Conflicting duplicate declarations are another special case. Usually the last of the duplicate declarations takes precedence.

Instructions

Instructions are XSLT elements occurring directly or indirectly inside top-level elements, specifically in sequence constructors (sequence constructors) within template rules defined by xsl:template. XSLT 1.0 calls the same concept, slightly less generally, template bodies (template bodies).

A brief comparison follows:

XSLT 1.0: The template body

In XSLT 1.0, a template body (template body) means not only a template rule’s immediate content, but any instruction block inside an instruction or sub-instruction that directly or indirectly generates result-tree content as nodes.

For example, loop instruction xsl:for-each contains a template body outputting content directly to the result. xsl:variable instead contains a template body creating a temporary tree and binding it to the variable for later use.

XSLT 2.0: The sequence constructor

XSLT 2.0 generalizes template bodies into a sequence constructor (sequence constructor), following XPath 2.0 terminology, which replaces node sets with general composite sequences of items that can include not only nodes but strings, numbers, dates or values of any other type.

A sequence constructor can therefore theoretically return non-node and mixed results. Like a template body, its sequence can be output directly as part of a result sequence or bound to a variable as a temporary tree (temporary tree).

The stylesheet as a well-formed XML document

Instruction order, nesting and frequency in template bodies or sequence constructors are generally unrestricted, with some exceptions. However, the stylesheet must respect the well-formedness rules. Two top-level elements, xsl:param and xsl:variable, can also be instructions, the latter at any position.

As an exception, xsl:param elements used as instructions must be the first children in a template rule, or in XSLT 2.0 also a function declaration. It must also be possible to supply a value to them. Unlike xsl:variable, they therefore do not belong to instructions generally allowed anywhere in template bodies or sequence constructors.

A similar restriction applies to another group not formally named. For example, xsl:when is permitted only within xsl:choose, and xsl:output-character only within declaration xsl:character-map. Members of this loosely defined group are therefore sometimes called sub-instructions.

Non-XSLT elements and text

This level, inside sequence constructors or template bodies, also permits literal result elements (literal result elements), meaning elements and attributes outside the XSLT namespace declared at the root. They are passed literally, as they are, into the result. Their namespaces are copied too, unless explicitly excluded.

Text nodes are also copied inside sequence constructors and are often loosely grouped with literal result elements. More precisely, they should be called literal data characters.

   

  

back to top