Conditionals in XSLT are either an unary "if":
<xsl:if test="some Boolean condition">
<!-- "if" stuff (there is no "else" here) -->
</xsl:if>
or more like the switch statement of other languages:
<xsl:choose>
<xsl:when test="some Boolean condition">
<!-- "if" stuff -->
</xsl:when>
<xsl:otherwise>
<!-- "else" stuff -->
</xsl:otherwise>
</xsl:choose>
where there is room for as many <xsl:when>
s as you like.
Every XPath expression can be evaluated as a Boolean according to a set of rules. These (for the most part) boil down to "if there is something -> true
" / "if there is nothing -> false
"
- the empty string is
false
- 0 is
false
(so is NaN
)
- the empty node set is
false
- the result of
false()
is false
- every other literal value is
true
(most notably: 'false'
is true
)
- the result of expressions is evaluated with said rules (no surprise here)