The context() Function
Release 2.0 - ...
Syntax
Copy Code | |
---|---|
node-set context() |
Description
This function returns the in-scope evaluation context node of the nearest ancestor element of the node containing the XPath expression that invokes this function.
The nearest ancestor element may have been created dynamically as part of the run-time expansion of repeated content.
Example
XML | Copy Code |
---|---|
<xforms:model> <xforms:instance id="fruitInstance" > <fruitRoot xmlns=""> <fruit>apple</fruit> <fruit>orange</fruit> <fruit>mandarine</fruit> <fruit>tomato</fruit> <bad-fruit>Unknown</bad-fruit> </fruitRoot> </xforms:instance> </xforms:model> ... <xforms:group> <xforms:output ref="instance('fruitInstance')/bad-fruit"> <xforms:label>Bad Fruit picked : </xforms:label> </xforms:output> </xforms:group> <xforms:group> <xforms:repeat nodeset="instance('fruitInstance')/fruit" id="fruits-repeat"> <xforms:trigger> <xforms:label ref="."/> <xforms:action ev:event="DOMActivate"> <xforms:setvalue ref="instance('fruitInstance')/bad-fruit" value="context()"/> </xforms:action> </xforms:trigger> </xforms:repeat> </xforms:group> |
The above example will initially display "Unknown" for the Bad Fruit picked output. When one of the triggers is activated, the value of the bad-fruit node will be updated with the value of the corresponding node of the trigger due to the context() usage within the value attribute of the setvalue XForms action.
Specification
Link to the XForms specification: the context() function.