The current() Function

Release 2.0 - ...

Syntax

  CopyCode image Copy Code
node-set current()

Description

Returns the context node used to initialize the evaluation of the containing XPath expression.

Example

XML CopyCode image Copy Code
<xforms:model >
   <xforms:instance xmlns="">
      <converter>
         <amount>100</amount>
         <currency>jpy</currency>
         <convertedAmount></convertedAmount>
      </converter>
   </xforms:instance>
   <xforms:instance xmlns="" id="convTable">
      <convTable date="20040212" currency="cdn">
         <rate currency="eur">0.59376</rate>
         <rate currency="mxn">8.37597</rate>
         <rate currency="jpy">80.23451</rate>
         <rate currency="usd">0.76138</rate>
      </convTable>
   </xforms:instance>
   <xforms:bind nodeset="convertedAmount"
        calculate="../amount * instance('convTable')/rate[@currency=current()/../currency]" />
</xforms:model>
...
<xforms:output ref="convertedAmount">
   <xforms:label>Converted Amount :</xforms:label>
</xforms:output>

Within the above example, the calculate model item property contains an XPath expresssion using the instance function to select a rate node. The rate node selected depends on the @currency attribute filter expression. This filter expression uses the current() function to retrieve the context node (convertedAmount in this case) and from there on construct an XPath expression to get the currency node from the default instance.

Since the currency node from the default instance contains the value jpy the second part of the calculate expression will return "80.23451", so the converted amount will equal 100 times that value.

Notice that this XPath expression could also have been written as "../amount * instance('convTable')/rate[@currency=instance()/currency]".

Specification

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