RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Home » Tip Bank » XML » XSLT
Language: XML
Expertise: Intermediate
Oct 2, 2006

Compatible Stylesheets with xsl:fallback

The following code is an example of how to use the xsl:fallback element to achieve full compatibility between XSLT different versions.

Imagine that some future 5.0 version of XSLT implements an <xsl:condition> element. Processors using earlier versions of XSLT wouldn't understand that element, so you can include an <xsl:fallback> element to enable the processor to continue, using elements it understands from an earlier version of XSLT.

<xsl:stylesheet version="5.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

<xsl:for-each select="***XPath expression***" >
   <xsl:condition test="***any condition***">
      XSLT 5.0 - OK - XSLT 5.0
            <xsl:if test="***any condition***">
               XSLT 1.0 - OK - XSLT 1.0
A processor using XSLT 1.0/2.0 will fail to recognize the <xsl:condition> element, but because it contains an <xsl:fallback> element the older processor will evaluate the <xsl:if> test in the <xsl:fallback> element instead of throwing an error.

Leonard Anghel
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date