How Do I Implement an if-else Statement?

For whatever reason, XSLT doesn’t provide an <xsl:else> element. To create an if-else statement, you need an <xsl:choose> element with a single <xsl:when> element and a single <xsl:otherwise> element. If the test attribute of the <xsl:when> element is true, then the contents of the <xsl:when> are evaluated; if not, the contents of the <xsl:otherwise> element are.

See the <xsl:choose> entry in Appendix A for a complete discussion of this element and some examples.

Get XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.