RationaleOrbeon 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<xforms:group> or <xforms:repeat> elements.The variable elementYou define variables with the extension element:
The element supports the following attributes:
NOTE: You can also use <exforms:variable> in the eXforms namespace. Variables within <xforms:model>Directly under the<xforms:model> element, the following rules apply:
<xhtml:head>Variables declared by <xforms:bind> elementsBind elements with a name attribute automatically declare a corresponding variable, as if using <xxforms:variable>.[TODO: example + describe scoping:
See also known issue: [ #315833 ] Variables leading to unexpected result inside an <xforms:bind> "iteration] Variables outside <xforms:model>Outside of models, the following rules apply:
<xhtml:body><!-- variable pointing to all the item children --> <!-- It uses the variable declared above --> <xxforms:variable name="items" value="$instance/item"/><!-- The code below uses the variables in scope --> <xforms:repeat nodeset="$items" id="items-repeat">Variables within <xforms:action>Variables are allowed within <xforms:action> elements, whether those elements are used within models or controls.<xforms:model>These variables are defined within the model --> <xxforms:variable name="foo" value="foo"/>This variable is defined within the group control and has access to the in-scope model variables --><!-- This variable is defined within the action and has access to all the variables in scope --> </xforms:action>The <xxforms:sequence> elementLike in XSLT, you can nest an <xxforms:sequence> element within <xxforms:variable>. The element supports the following attributes:
This allows you to decouple the variable definition (name) from its evaluation: <xxforms:variable name="sum">This is particularly useful for XBL component implementors, where this can be used in combination with the xxbl:scope attribute: <xxforms:variable name="result" as="node()?">Single-node attributes may be used on the <xxforms:sequence> element. Scoping of variables in the viewThe following guidelines apply when using variables in the view:
Example: <xhtml:html> <xhtml:head> <xforms:model id="model1"> <xforms:instance> <instance> <foo>42</foo> </instance> </xforms:instance> <xxforms:variable name="foo" value="foo"/> </xforms:model> <xforms:model id="model2"> <xforms:instance> <instance> <foo>44</foo> </instance> </xforms:instance> <xxforms:variable name="foo" value="foo"/> </xforms:model> </xhtml:head> <xhtml:body> <!-- Top-level --> <!-- model1 is the default model: $foo from model1 is visible --> <xxforms:variable name="gaga" value="41"/> <!-- $gaga is visible because preceding in the view --> <xforms:group model="model2"> <!-- model2 is the current model: $foo from model2 is visible --> <xxforms:variable name="toto" value="43"/> <!-- $gaga and $toto are visible because they are preceding in the view --> <xforms:group model="model1"> <!-- model1 is the current model: $foo from model1 is visible, and $gaga is visible --> <!-- $gaga and $toto are visible because they are preceding in the view --> </xforms:group> </xforms:group> </xhtml:body></xhtml:html>Current limitationsAs of 2011-03, the implementation has the following limitations:
|