August 2001
Intermediate to advanced
480 pages
11h 16m
English
<xsl:fallback> — Defines a template that should be used when an extension element can’t be found.
Instruction
None.
None.
An XSLT template.
<xsl:fallback> appears inside a template.
XSLT section 15, Fallback.
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 ...