XML technologies / XSLT / Reference: XSLT 1.0 and 2.0 elements / fallback

(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 xsl:fallback element provides alternative code when the XSLT runtime does not support its parent instruction.

Classification

Instruction

Function group

Alternative code for backward compatibility

Introduced

XSLT 1.0

Position in the stylesheet and permitted contents:

xsl:fallback is a child in an XSLT or extension instruction’s block. Multiple xsl:fallback elements may appear consecutively.

An xsl:fallback element contains a sequence constructor or template body comprising arbitrary XSLT instructions, Literal Result Elements and text.

Attributes:

Standard attributes apply. Instruction xsl:fallback has no attributes of its own.

Purpose:

The xsl:fallback element contains an alternative template block instantiated when the containing instruction is unsupported by the XSLT processor. This may be an unknown extension instruction or an XSLT instruction from a newer version than the processor implements.

If multiple xsl:fallback elements occur within the unrecognized instruction, all run in their order of appearance.

The principle enabled by xsl:fallback, known as forwards-compatible processing (forwards-compatible behavior), aims to let a processor execute as much of a stylesheet as possible despite unsupported instructions.

If the processor encounters an unknown extension instruction without a xsl:fallback element, it must report a runtime error, or dynamic error, and stop processing (ERR XTDE1450).

Warning – Not for top-level elements!
Fallback works only for instructions, not unsupported top-level elements. An unrecognized top-level declaration is simply ignored.

Example – New XSLT instruction:

<xsl:template match="/">
  ...
  <xsl:superfeature version="3.0">
  <!-- neue, nie da gewesene Möglichkeiten -->
    <xsl:fallback>
      <xsl:message>Leider wird diese Instruktion nicht unterstützt!</xsl:message>
    </xsl:fallback>
    <xsl:fallback>
      <xsl:message>Da ist wohl ein neuer XSLT-Prozessor fällig...</xsl:message>
    </xsl:fallback>
  </xsl:superfeature>
  ...
</xsl:template>

If an unknown instruction provides xsl:fallback elements, all alternative blocks run, two in this case.

Note: attribute version with value "3.0" alone would put an XSLT 2.0 processor in forwards-compatible mode, even if it recognized the instruction.

Element definition:

XSLT 1.0:

<!-- Category: instruction -->
<xsl:fallback>
     <!-- Content: template -->
</xsl:fallback>

XSLT 2.0:

<!-- Category: instruction -->
<xsl:fallback>
     <!-- Content: sequence-constructor -->
</xsl:fallback>

Cross-references:

See also XSLT function element-available().

   

  

back to top