Share via


<xsl:fallback> Element

The <xsl:fallback> element is designed to handle XSLT elements that cannot be handled by the parser: for example, elements that are part of a new version or unrecognized extension. The <xsl:fallback> element works by calling template content that provides a reasonable substitute for the behavior of the new element.

<xsl:fallback>
</xsl:fallback>

Attributes

None

Element Information

Number of occurrences

Unlimited

Parent elements

xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, outputelements

Child elements

xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

Remarks

When an XSLT document is first loaded, the XSLT preparser performs validation on all XSLT elements. If the version passed in the <xsl:stylesheet> element is greater than that supported by the parser, the parser will execute the <xsl:fallback> children of any unfamiliar element that is encountered. If an <xsl:fallback> element has no content, the parser does not perform any action. If an element is supported, the templates in its <xsl:fallback> children are never instantiated. If the version given in the style sheet is the same as that supported by the browser, an error will be called.

Fallbacks are part of the forward-processing mechanism that XSLT uses for handling upgrades. By creating alternative ways of handling a command if an element is not supported, forward-processing guarantees that the code used is relatively robust and insensitive to differences in parser conformity.

In addition to handling versioning differences, the fallback mechanism can also be used to handle elements defined by namespace extensions. Because adding functionality to the base specification is typically very difficult, namespace extensions let developers define functionality beyond that specified by the XSLT specification. If the namespace is not supported (no definition for the namespace is provided), or if a namespace function or element is not defined, the fallback mechanism can be used to provide alternate functionality.

To guarantee that the extension is interpreted within the XSLT operation, you need to set the extension-element-prefixes attribute in the <xsl:stylesheet> element so that it contains the name of the prefix to interpret. In addition, declare the namespace for that prefix.

The following topic provides an example of <xsl:fallback>.