I know this may seem like a dumb/newbie question, but I'm fairly new to XSLT (though I'm starting to come around to it and see it's capabilities).
When is it appropriate to use xsl:if and when is it appropriate to use xsl:choose/xsl:when?
I have been using choose/when/otherwise when I want to have an "else" option. Is this correct?
For instance I have some places where I'm doing:
<xsl:choose>
<xsl:when test="count(entry) != 0">
put positive outcome here
</xsl:when>
<xsl:otherwise>
put something else here
</xsl:otherwise>
</xsl:choose>
would xsl:if be better?
Thanks for the input.
Use xsl:if for simple cases where you just want to test if an expression is true. (Note that there is no corresponding xsl:else.)
<xsl:if test="expression">
output if the expression is true
</xsl:if>
Use xsl:choose for cases where you have some alternate output when the expressions is false.
<xsl:choose>
<xsl:when test="expression">
output if the expression is true
</xsl:when>
<xsl:otherwise>
output if the expression is false
</xsl:otherwise>
</xsl:choose>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With