xsl:if

Used for conditional processing. It takes a mandatory test attribute, whose value is a boolean expression. The contents of the xsl:if element are expanded only of the expression is true.

Category: instruction
Content: sequence-constructor
Permitted parent elements: any XSLT element whose content model is sequence-constructor; any literal result element

Attributes

test

expression

The boolean expression to be tested. The full syntax of boolean expressions is outlined in XPath Expression Syntax.

Examples

Includes a hyperlink in the output only if the current element has a preface attribute:

<xsl:if test="@preface"> <a href="preface.html">Preface</a> </xsl:if>

Links to W3C specifications

XSLT 2.0 Specification

XSLT 3.0 Specification

See also

xsl:choose