在XSLT/xpath2或更高版本中,很容易简单地提供一个序列
(ns2:metadata/ns2:mainTitle, ns1:info/ns1:title, ns2:metadata/ns2:altTitle, 'Fallback')
(ns2:metadata/ns2:mainTitle, ns1:info/ns1:title, ns2:metadata/ns2:altTitle, 'Fallback')[1]
根据第一个可用项进行选择。
在XSLT1中,用简洁而优雅的方式表达这一点更加困难,也许您可以使用硬编码的
xsl:choose
:
<xsl:choose>
<xsl:when test="ns2:metadata/ns2:mainTitle">
<xsl:value-of select="ns2:metadata/ns2:mainTitle"/>
</xsl:when>
<xsl:when test="ns1:info/ns1:title">
<xsl:value-of select="ns1:info/ns1:title"/>
</xsl:when>
<xsl:when test="ns2:metadata/ns2:altTitle">
<xsl:value-of select="ns2:metadata/ns2:altTitle"/>
</xsl:when>
<xsl:otherwise>Fallback</xsl:otherwise>
</xsl:choose>
可能包装在可调用或可应用(可能使用模式)模板中。