You use the XSLT 1.0 <xsl:fallback> element to indicate what to do if an extension element is not available. This element is enclosed in the extension element and is used if the extension element isnt available.
The <xsl:fallback> element has no attributes, and encloses a template body.
In the following example, I create a fallback element inside the <redirect:write> element from the previous example. The <xsl:fallback> element will terminate processing with a message if the <redirect:write> element isnt available:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:lxslt="http://xml.apache.org/xslt" xmlns:redirect="org.apache.xalan.lib.Redirect" extension-element-prefixes="redirect"> <lxslt:component prefix="redirect" elements="write open close" functions=""> <lxslt:script lang="javaclass" src="org.apache.xalan.lib.Redirect"/> </lxslt:component> <xsl:output method="xml"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="PLANETS"> <redirect:write select="@file"> <PLANETS> <xsl:apply-templates/> </PLANETS> <xsl:fallback> <xsl:message terminate="yes"> <xsl:text>Could not create multiple output documents.</xsl:text> </xsl:message> </xsl:fallback> </redirect:write> </xsl:template> <xsl:template match="@*node()"> <xsl:copy> <xsl:apply-templates select="@*node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
And thats it for this introduction to working with the data in XML documents. In the next chapter, Ill dig deeper into this topic to examine how to modify document contents, as well as how to create new elements, attributes, and processing instructions.