XML technologies / XSLT / Reference: XSLT 1.0 and 2.0 elements / Brief overview of XSLT 2.0

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

XSLT 2.0 retains all XSLT 1.0 elements, some with expanded capabilities, and adds elements usable by sufficiently recent processors. Set the stylesheet element’s version attribute to "2.0". Individual declarations or instructions can also carry a version attribute. XSTL 2.0 extends existing elements’ attribute sets and, in some cases, content models.

All elements now accept a standard attribute set, mainly covering namespaces and processing aspects, including the version attribute mentioned above. These and other element-specific extensions are described below and in the alphabetical reference of all XSLT elements.

XSLT 2.0 adds fourteen elements: three top-level elements, eight instructions and three subinstructions, bringing the total to 49.

Warning – XSLT 2.0 is not based on XSLT 1.1!
The new element xsl:script planned for the subsequently withdrawn XSLT 1.1 is omitted from XSLT 2.0. The XSLT 1.1 instruction xsl:document has its functionality covered in XSLT 2.0 by xsl:result-document. The same-named XSLT 2.0 instruction xsl:document validates unserialised document trees and is therefore different from the XSLT 1.1 instruction.

New top-level elements in XSLT 2.0

XSLT 2.0 adds three to the twelve top-level elements inherited from XSLT 1.0:

xsl:character-map

xsl:import-schema

xsl:function

Table: New top-level elements in XSLT 2.0.

The first addition is xsl:character-map, declaring named character mappings. During serialisation, it replaces specified characters with specified strings. The complementary instruction xsl:output-character is also introduced.

The second new top-level element, xsl:function, lets users declare functions and their return values. Bound to their defining stylesheet and its runtime, they are called stylesheet functions.

Another addition, xsl:import-schema, incorporates XML Schema files into processing, making user-defined data types available to XSLT.

New instructions and subinstructions in XSLT 2.0

XSLT 2.0 adds eight instructions to XSLT 1.0’s seventeen:

xsl:analyze-string

xsl:next-match

xsl:document

xsl:perform-sort

xsl:for-each-group

xsl:result-document

xsl:namespace

xsl:sequence

Table: New instructions in XSLT 2.0.

Three further subinstructions are also defined:

xsl:matching-substring

xsl:non-matching-substring

xsl:output-character

Table: New subinstructions in XSLT 2.0.

New XSLT 2.0 instructions solve problems difficult or impossible in XSLT 1.0. For example, xsl:analyze-string checks strings with regular expressions, using the subordinate instructions xsl:matching-substring and xsl:non-matching-substring.

The instruction xsl:document creates a document node as a temporary tree, optionally validating it. It complements the also new instruction xsl:result-document, described below, which does not use temporary trees.

The new instruction xsl:for-each-group simplifies grouping output nodes. Two associated XSLT functions are current-group() and current-grouping-key().

The instruction xsl:perform-sort returns sorted sequences by grouping several xsl:sort instructions into one sorting specification.

Node generation is completed by xsl:namespace, which creates namespace nodes.

The instruction xsl:next-match, like xsl:apply-imports, also activates matching template rules whose match (pattern ) has the next closest priority to the current rule for the node being processed.

With the top-level declaration xsl:character-map mentioned above, subinstruction xsl:output-character assigns a replacement string to a character in a collection of character mappings.

Producing multiple output documents in one pass, previously possible only with processor-specific extensions, enters the standard as xsl:result-document. The declaration xsl:output gains a name attribute to associate it with this instruction.

The instruction xsl:sequence generates a sequence of arbitrary types, for example to add to an existing sequence. It offers an alternative to XPath 2.0 expressions. In stylesheet functions defined by xsl:function, it generates the result sequence.

The figure shows XSLT 2.0 elements’ relationships and hierarchy:

Overview of XSLT 2.0 elements

Figure: Overview of XSLT 2.0 elements.

   

  

back to top