Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
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:fallback>
            <xsl:if test="***any condition***">
               XSLT 1.0 - OK - XSLT 1.0
            </xsl:if> 
         </xsl:fallback>
   </xsl:condition>				          
</xsl:for-each>
...
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
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap