<xf:bind>elements with a
nameattribute automatically declare a corresponding XPath variable, as if using
<xf:var>. This is an extension of the XForms specification.
Variable resolution attempts to find the "closest" associated target bind objects. In the following example, generated by Form Builder, there are variables associated with binds
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="my-section-bind" name="my-section" ref="my-section">
<xf:bind id="my-repeat-bind" ref="my-repeat" name="my-repeat">
<xf:bind id="col1-bind" ref="col1" name="col1" type="xf:decimal"/>
<xf:bind id="col2-bind" ref="col2" name="col2" type="xf:decimal"/>
<xf:bind id="rowsum-bind" ref="rowsum" name="rowsum"
calculate="sum(($col1, $col2)[string() castable as xs:decimal], 0.0)"
<xf:bind id="totalsum-bind" name="totalsum" ref="totalsum"
calculate="sum($rowsum[string() castable as xs:decimal], 0.0)"
calculateexpressions to refer to these variables:
rowsum-bindrefers, for each iteration of
my-repeat-bind, to the
$col2belonging to that same iteration.
totalsum-bind, on the other hand, refers to the $rowsum` in all iterations.
The result shows the expected sums:
More specifically, given the following:
- an expression on a given bind called below the context bind
- a target bind referred to by means of a variable name in that expression
The following algorithm is followed:
- 1.If the variable name refers to the context bind itself or one of its ancestors, the single node corresponding to the current bind iteration is returned.
- 2.Otherwise, if the context bind and the target bind share a common ancestor, all branches starting from the common iteration of that common ancestor bind are followed to all possible target bind objects, and all nodes associated with those target bind objects are returned.
- 3.Otherwise, if the context bind and the target bind do not share a common ancestor, all nodes associated with all target bind objects are returned.
If a bind referenced by a variable is within an unambiguous context, that is the context in which that bind evaluates is a single node, then the values of the bind's node-set is returned by the variable, otherwise the empty sequence is returned.
This means that target bind objects within more than one bind iteration cannot be accessed.