XSLT <xsl:fallback> 元素

定義和用法
The <xsl:fallback> 元素規定了在 XSL 處理器不支持 XSL 元素時,所運行的替代代碼。
語法
<xsl:fallback>
<!-- Content: template -->
</xsl:fallback>
<!-- Content: template -->
</xsl:fallback>
屬性
無
實例 1
本例本來是要使用一個虛構的 <xsl:loop> 元素來迴圈遍曆每個 "title" 元素。如果 XSL 處理器不支持該元素(它確實不支持),則會使用 <:xsl:for-each> 元素取而代之:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="catalog/cd">
<xsl:loop select="title">
<xsl:fallback>
<xsl:for-each select="title">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:fallback>
</xsl:loop>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="catalog/cd">
<xsl:loop select="title">
<xsl:fallback>
<xsl:for-each select="title">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:fallback>
</xsl:loop>
</xsl:template>
</xsl:stylesheet>
