Variable

The variable Element

The variable element introduces a variable to be used in XPath expression in the subtree of the parent to the variable element.

Attributes

name

Required

The name of the variable. This is a xsd:QName.

select

Required

[XPath 1.0] expression which is the value assigned to the variable. The expression is evaluated in the context defined by [XForms 1.0] and by the model attribute on this element.

model

Optional

The xforms model used for scoping which model the attribute correspons to.

For variables in the model they are updated before the processing of the xforms-recalculate event and for variable elements in the UI they are updated before the xforms-refresh event. A variable scope is defined in a model and from the parent of the variable element and the last one with the same name takes precedens. It must be possible to defined identical named variables for different model in the same document scope.

Erik's Notes

Example of variable in actions (here just using a variable for convenience, you can actually get by with context()):

<xforms:action iterate="a | b | c | d">
  <xforms:variable name="local-name" select="local-name()"/>
  <xforms:setvalue ref="@id" value="concat('id-', $local-name)"/>
</xforms:action>

Example: how to use variable in the UI

<xforms:model> 
  <xforms:instance>
    <data xmlns="">
      <a><b><c>value</c></b></a>
    </data>
  </xforms:instance>
</xforms:model>

<xforms:group>
  <xforms:variable name="bvalue" select="a/b"/>
  
  The c value: <xforms:output ref="$bvalue/c"/>
</xforms:group>

Example: how to use variable in the model

<xforms:model> 
  <xforms:instance>
    <data xmlns="">
      <a><b><c>value</c></b></a>
    </data>
  </xforms:instance>

  <xforms:variable name="bnode" select="a/b"/>
  <xforms:variable name="boolean" select="$bnode/c = 'value'"/>

  <xforms:bind nodeset="$bnode" relevant="$boolean"/>
</xforms:model>

More of Erik's notes about variables related to the proposed @name attribute

Erik needs to clean this up ;-)


CategoryXFormsFutureFeatures

Variables in XPath (last edited 2008-06-27 02:12:24 by ErikBruchez)