The <xsl:if> Element

You use <xsl:if>to make tests and take different actions depending on the result of the test. It’s much like the ifstatement in programming languages. The <xsl:if> element has one attribute:

  • test(mandatory). Set to a Boolean (true/false) condition that you want tested.

This element encloses a template body.

Here’s how it works: You enclose a template body inside the <xsl:if> element, which tests some expression. If that expression evaluates to true, the template body is used, but if the expression evaluates to false, the template body is ignored:

<xsl:if test="expression"> 
    <!--template body--> 

You can test any XPath expression. Use the following rules for converting them to true/false in the <xsl:if> element: ...

Get Inside 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.