So we have just implemented in Orbeon Forms the following convenient functions:
Usage is very simple. In this example, when the user presses the button, the current value of the label is displayed in a message:
This raised a small design question: is it better to write xxf:label('id'), or xxf:lhha('id', 'label')? We have opted for the former, which is more explicit and better typed. Also, it doesn't seem like many more similar control properties will be added in the future.
The functions are also documented on the Orbeon Forms wiki.
The functions are also documented on the Orbeon Forms wiki.
For the curious, the implementation of these 4 functions is really simple in a single short Scala class, and it plugs very nicely into the Saxon XPath engine:
Note the uses of:
- pattern matching: case control: XFormsControl if control.isRelevant =>
- a nested function: evaluateControlItem is local to evaluateItem
- first-class functions: XFormsControl.getLabel, etc. are passed as a parameter to evaluateControlItem
In this case, the implementation would probably not have been outrageously different in Java: we would have used if instead of match, a private method instead of a local function, and passed one of the LHHA values to that private method instead of passing functions around.