fallback_1-input.xml
<?xml version="1.0"?>
<products>
<product
id="p1" price="3250" stock="4" country="Denmark"/>
<product
id="p2" price="1000" stock="5" country="Germany"/>
<product
id="p3" price="1200" stock="19" country="Germany"/>
<product
id="p4" price="1500" stock="5" country="Australia"/>
<product
id="p5" price="1225" stock="3" country="Japan"/>
</products>
fallback_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output
indent="yes"/>
<xsl:template
match="/">
<xsl:variable
name="product">
<xsl:perform-sort
select="products/product">
<xsl:sort
select="@stock" data-type="number" order="descending"/>
<xsl:sort
select="@country" order="ascending"/>
<xsl:fallback>
<xsl:for-each
select="products/product">
<xsl:sort
select="@stock" data-type="number" order="descending"/>
<xsl:sort
select="@country" order="ascending"/>
<product
id="{@id}" price="{@price}" stock="{@stock}" country="{@country}"/>
</xsl:for-each>
</xsl:fallback>
</xsl:perform-sort>
</xsl:variable>
<products>
<xsl:copy-of
select="$product"/>
</products>
</xsl:template>
</xsl:stylesheet>
fallback_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product
id="p3" price="1200" stock="19" country="Germany"/>
<product
id="p4" price="1500" stock="5" country="Australia"/>
<product
id="p2" price="1000" stock="5" country="Germany"/>
<product
id="p1" price="3250" stock="4" country="Denmark"/>
<product
id="p5" price="1225" stock="3" country="Japan"/>
</products>
This XSLT 2.0 stylesheet has been tested with the following XSLT 1.0 processors. In Oxygen: Success in MSXML 3.0, MSXML 4.0, .Net 1.0, .Net 2.0, and in Xalan; errors in Saxon 6.5.5 and in Xsltproc. In XMLSpy: Errors in MSXML 3.0, 4.0 and 6.0! In Stylus Studio: Success in build-in Java processor, and in all Microsoft's processors!
Updated 2009-03-19