If conditions

An If element encloses any fragment of a template that should only apply under special circumstances. The condition is defined using the Test attribute, which holds an expression:

<if
					test="...">
  ...
  <!-- OPTIONAL FRAGMENT OF TEMPLATE -->
  ...
</if>

The expression must return a boolean result. A value of 'true' unlocks the content of the If element for use in the template. A value of 'false' indicates a failed test, and the content of the If element is ignored.

A template fragment can therefore be marked, then explicitly included or excluded using the 'true()' and 'false()' expressions:

<if test="true()">
  ...
  <!-- REQUIRED FRAGMENT OF TEMPLATE -->
  ...
</if>


<if test="false()">
  ...
  <!-- IGNORED FRAGMENT OF TEMPLATE --> ... </if> ...

Get XSL companion, The 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.