Variables
Last updated
Last updated
Orbeon Forms supports declaring variables which look and behave very much like XSLT variables. Variables are extremely useful, for example to avoid repeating long XPath expressions, or to give an XPath expression unambiguous access to data computed in enclosing <xf:group>
or <xf:repeat>
elements.
You define variables with the extension element:
For backward compatibility, the following elements are still supported:
<xxf:variable>
<exf:variable>
(in the eXforms namespace)
The element supports the following attributes:
The expression is evaluated in the element's single-item binding if present, otherwise in the context of its parent.
If the value
attribute is omitted, the text content of the <xf:var>
element is used as the value.
Directly under the <xf:model>
element, the following rules apply:
Variables are supported directly under the <xf:model>
element.
Model variables are evaluated in the order in which they appear in the model.
All model variables are visible to other model elements such as <xf:bind>
or <xf:submission>
.
Model variables are also visible from XPath expression outside of models whenever that model is in scope.
See XForms: Model bind variables.
Outside of models, the following rules apply:
Variables are supported anywhere XForms controls are allowed.
A given variable is visible to any XPath expression on a following sibling element or on a following sibling element's descendant element.
Variables are allowed within <xf:action>
elements, whether those elements are used within models or controls.
You can nest an <xxf:value>
element within <xf:var>
.
NOTE: The <xxf:value>
element replaces the deprecated <xxf:sequence>
element but works exactly the same way. Until Orbeon Forms 4.6 included, you must use the element <xxf:sequence>
. From Orbeon Forms 4.7 onward, use <xxf:value>
.
The element supports the following attributes:
The expression is evaluated in the element's single-item binding if present, otherwise in the context of its parent <xf:var>
element. If the attribute is omitted, the text content of the <xxf:value>
element is used as the value.
This allows you to decouple the variable definition (name) from its evaluation:
This is particularly useful for XBL component implementors, where this can be used in combination with the xxbl:scope
attribute:
Single-item attributes may be used on the <xxf:value>
element.
The following guidelines apply when using variables in the view:
Only variables in the current XBL scope are visible
All preceding view variables are visible even across changes of models (with model="...")
Finally, the current model's variables are visible
Variable hiding applies between view variables and model variables
Example:
The <xf:var>
element has the following limitations:
The as
attribute is ignored but can be used for documentation purposes.
Cannot be used within XForms leaf controls such as <xf:input>
, including within nested items or itemsets (except within <xf:action>
elements, where they are allowed).
Cannot be used within nested model elements, including <xf:bind>
or <xf:submission>
(except within <xf:action>
elements, where they are allowed).
name
mandatory
name of the variable
as
optional
type of the variable (ignored but can be used for documentation purposes)
model
optional
contributes to the variable's single-item binding
context
optional
contributes to the variable's single-item binding
ref
optional
contributes to the variable's single-item binding
bind
optional
contributes to the variable's single-item binding
value
optional
XPath 2.0 expression determining the value of the variable
model
optional
contributes to the element's single-item binding
context
optional
contributes to the element's single-item binding
ref
optional
contributes to the element's single-item binding
bind
optional
contributes to the element's single-item binding
value
optional
XPath 2.0 expression determining the value of the variable