The choose() Function
Release 2.0 - ...
Syntax
Copy Code | |
---|---|
object choose(boolean, object, object) |
Description
This function provides a conditional test that chooses an object to return based on the boolean parameter. If the boolean parameter is true, then the first object is returned, otherwise the second object is returned. Each of the object parameters can be of any XPath datatype, and this function does no type conversion of the parameter it chooses to return.
Example
XML | Copy Code |
---|---|
<xforms:model > <xforms:instance xmlns=""> <petlist> <dogs> <dog name="Benji" /> <dog name="Cujo" /> <dog name="Lassie" /> </dogs> <cats> <cat name="Garfield" /> <cat name="Heathcliff" /> <cat name="Felix" /> <cat name="Tom" /> </cats> </petlist> </xforms:instance> </xforms:model> ... <xforms:repeat nodeset="choose(count(dogs/dog) > count(cats/cat), dogs/dog, cats/cat)"> <xforms:output ref="@name"> <xforms:label>Nodeset : </xforms:label> </xforms:output> </xforms:repeat> |
The above example will display the name attributes from the cats/cat nodes (Garfield, Heatcliff, Felix and Tom respectively), since the boolean expression equals false.
Specification
Link to the XForms specification: the choose() function.