The if:if Element

Use the if:if element in any block context to make one or more block elements conditional. The if:if element is more convenient than the if:test attribute for multiple block elements, but simpler than the if:choose and if:when elements when there is only one condition.


  • The if:if element can contain any general block content.

  • The if:if element can occur in any general block context.

  • The required test attribute contains a test expression that determines whether the content of the if:if element will be displayed.

  • The style attribute takes a space-separated list of style hints. Processing tools should adjust their behavior according to those style hints they understand.

  • The if:if element can have attributes from external namespaces. See External Namespaces for more information on external-namespace attributes.


Only show a paragraph when outputting to HTML:

<if:if test="target:html">
  <p>This is only output to HTML.</p>

The previous example could have been done more easily with the if:test attribute on the p element. Use the if:if element to enclose multiple paragraphs in a single condition:

<if:if test="target:html">
  <p>This is only output to HTML.</p>
  <p>So is this.</p>
  <p>As well as this.</p>

See Examples on the page The test and if:test Attributes for examples of more complicated test expressions.

Processing Expectations

The test attribute of an if:if element is evaluated as a test expression according to the processing instructions of the test attribute. If the expression evaluates to true, the children of the if:if element are processed in block context. Otherwise, the entire if:if element is skipped.

Processing tools that do not support this extension will process the children in restricted block context. This means that all standard block content of an if:if element will be displayed by non-supporting tools. See Fallback Behavior for more details.


The formal definition of the Mallard Conditionals extension is maintained in RELAX NG Compact Syntax in code blocks within this specification. This is the formal definition for the if:if element. The namespace declarations for this definition are on the page Conditionals 1.0.

if_if = element if:if {
  mal_block *
if_if_attr = (
  attribute style { xsd:NMTOKENS } ?,
  mal_attr_external *
mal_block_elements |= if_if
© 2011, 2012 Shaun McCance
cc-by-sa 3.0 (us)

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

As a special exception, the copyright holders give you permission to copy, modify, and distribute the example code contained in this document under the terms of your choosing, without restriction.

Powered by