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--> 
</xsl:if> 

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.