SEM Labs

Handcrafted Pixels, Code & Title Tags

If

Elements

The XFL if element decides whether its child nodes should be processed based on an expression. If the expression returns false, the child nodes are removed from the document. For example adding a class on an input field.

Dissection of the XFL If Element

Syntax

Attributes

Attribute Value Description Required
test XPath expression XPath expression to evalueate Yes

Test Attribute

The test attribute defines an XPath query which will be evaluated against the data document. When the expression returns true, the contents of the if element are processed; else they are removed and not processed. As well as supporting XPath syntax, XFL variables can be used in the expression.

Basic Example

The following example shows how a message could be displayed inline when a password and password_confirm field don't match:

When the submitted password and password_confirm values don't match the following HTML will be outputed:

Variable Example

The following example show how a message could be displayed inline when a password doesn't match the value of an XFL variable:

When the submitted password and $password values don't match the following HTML will be outputed: