The if() Function
Release 2.0 - ...
Syntax
|
|
|
|---|---|
string if(boolean, string, string) |
|
Description
Function if() evaluates the first parameter as boolean, returning the second parameter when true, otherwise the third parameter.
Example
| XML |
|
|---|---|
<xforms:model xmlns:ex="http://example.com">
<xforms:instance>
<ex:driver>
<ex:age>18</ex:age>
<ex:points>12</ex:points>
</ex:driver>
</xforms:instance>
</xforms:model>
...
<xforms:group>
<xforms:output value="if(ex:age > 17, 'Yes', 'No')">
<xforms:label>Adult : </xforms:label>
</xforms:output>
</xforms:group>
<xforms:group>
<xforms:output value="if(ex:points < 6, 'Safe', 'Unsafe')">
<xforms:label>Safety : </xforms:label>
</xforms:output>
</xforms:group>
|
|
The above example returns "Yes" and "Unsafe" respectively.
Specification
Link to the XForms specification: the if() function.