[UP]
The UI language
 ui:a
 ui:alist-value and ui:alist-item
 ui:application
 ui:button
 ui:checkbox
 ui:cond
 ui:context
 ui:default
 ui:dialog
 ui:dyn-enum-value and ui:dyn-enum-item
 ui:dynamic
 ui:encode
 ui:enum-value and ui:enum-item
 ui:enumerate
 ui:enumeration and ui:enum
 ui:false
 ui:file
 ui:form
 ui:if
 ui:iflang
 ui:ifvar
 ui:imagebutton
 ui:iter-*
 ui:iterate
 ui:page
 ui:param
 ui:popup
 ui:radio
 ui:richbutton
 ui:select
 ui:server-popup
 ui:special
 ui:string-value
 ui:template
 ui:text and ui:password
 ui:textarea
 ui:translate
 ui:true
 ui:use
 ui:variable
 t:*, q:*, and p:*
 l:*
 $param
 $[expr]
 Dot notation (v1.v2)
   
The element ui:if

This element compares two values. If the result is true, the inner nodes are expanded and the condition code is set to true; otherwise the inner nodes are ignored, and the conditon code is set to false.

Declaration

Level: Control structure

<!ENTITY % string-operators
           'eq|ne|match|nomatch'>
<!ENTITY % int-operators
           'int-eq|int-ne|int-lt|int-le|int-gt|int-ge'>
<!ENTITY % operators
           '%string-operators;|%int-operators;'>

<!ELEMENT ui:if ANY>

<!ATTLIST ui:if
          value1   CDATA         #REQUIRED
          value2   CDATA         #REQUIRED
          op       (%operators;) "eq"
>

Attributes

  • value1: The first operand of the comparison

  • value2: The second operand of the comparison

  • op: The comparison operator

Sub elements

All page body elements may occur as sub elements.

Operators

The following operators are defined for ui:if:

  • eq: string equality

  • ne: string inequality

  • match: the first operand matches the regular expression denoted by the second operand (see notes on regular expressions below)

  • nomatch: the first operand does not match the regular expression denoted by the second operand (see notes on regular expressions below)

  • int-eq: integer equality

  • int-ne: integer inequality

  • int-lt: the first operand is less than the second operand

  • int-le: the first operand is less or equal than the second operand

  • int-gt: the first operand is greater than the second operand

  • int-ge: the first operand is greater or equal than the second operand

Regular expressions

The engine matching regular expressions is PCRE (Perl-compatible regular expressions), so the Perl syntax is used. The expressions are not anchored by default, so have to write ^ and $$ to force anchoring. ^ matches the beginning of the string, and $$ matches the end of the string ("single-line expressions"). Note that you have to write double dollars $$ because the dollar character is the escape character for template parameters.

Hints

Note that template parameters and bracket expressions within ui:if are unconditionally evaluated. See ui:cond for a discussion of the consequences of this fact.

Example

<ui:if value1="$[n]" value2="1" op="gt">
  The result has more than one solution: ...
</ui:if>