<xsl:fallback> |
Defines a template that should be used when an extension element can't be found.
Category
Instruction
Required Attributes
None.
Optional Attributes
None.
Content
An XSLT template.
Appears in
<xsl:fallback> appears inside a template.
Defined in
XSLT section 15, Fallback.
Example
Here is a stylesheet that uses <xsl:fallback> to terminate the transformation if an extension element can't be found:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:db="xalan://DatabaseExtension"
      extension-element-prefixes="db">

      <xsl:output method="html"/>

      <xsl:template match="/">
        <html>
          <head>
            <title><xsl:value-of select="report/title"/></title>
          </head>
          <body>
            <h1><xsl:value-of select="report/title"/></h1>
            <xsl:for-each select="report/section">
              <h2><xsl:value-of select="title"/></h2>
              <xsl:for-each select="dbaccess">
                <db:accessDatabase>
                  <xsl:fallback>
                    <xsl:message terminate="yes">
                      Database library not available!
                    </xsl:message>
                  </xsl:fallback>
                </db:accessDatabase>
              </xsl:for-each>
            </xsl:for-each>
          </body>
        </html>
      </xsl:template>

    </xsl:stylesheet>
When we use this stylesheet to transform a document, the <xsl:fallback> element is processed if the extension element can't be found:
    Database library not available!

    Processing terminated using xsl:message
In this case, the extension element is the Java class DatabaseExtension. If, for whatever reason, that class can't be loaded, the <xsl:fallback> element is processed. Note that the <xsl:fallback> element is processed only when the extension element can't be found; if the code that implements that extension element is found, but fails, it must be handled some other way. Also be aware that the exact format of the message and the gracefulness of stylesheet termination will vary from one XSLT processor to the next.