The instance() Function

Release 2.0 - ...

Syntax

  CopyCode image Copy Code
node-set instance(string?)

Description

An XForms Model can contain more than one instance. This function allows access to instance data, within the same XForms Model, but outside the instance data containing the context node.

If the argument is omitted or is equal to the empty string, then the root element node (also called the document element node) is returned for the default instance in the model that contains the current context node.

Otherwise, the argument is converted to a string as if by a call to the string() function. This string is treated as an IDREF, which is matched against instance elements in the containing document. If a match is located, and the matching instance data is associated with the same XForms Model as the current context node, this function returns a node-set containing just the root element node (also called the document element node) of the referenced instance data. In all other cases, an empty node-set is returned.

Example

XML CopyCode image Copy Code
<xforms:model>
   <xforms:instance id="defaultInstance" >
      <orderForm xmlns="">
         <shipTo>
            <firstName>George</firstName>
         </shipTo>
      </orderForm>
   </xforms:instance>
   <xforms:instance id="orderform">
      <orderForm xmlns="">
         <shipTo>
            <firstName>John</firstName>
         </shipTo>
      </orderForm>
   </xforms:instance>
</xforms:model>
...
<xforms:group>
   <xforms:output ref="instance('orderform')/shipTo/firstName">
      <xforms:label>First Name : </xforms:label>
   </xforms:output>
</xforms:group>
<xforms:group>
   <xforms:output ref="instance()/shipTo/firstName">
      <xforms:label>Second Name : </xforms:label>
   </xforms:output>
</xforms:group>

The above example will display "John" (as First Name) and "George" (as Second Name) respectively.

Specification

Link to the XForms specification: the instance() function.