xforms:bind

Attaches properties and constraints to a nodeset in the model.

Syntax

<xforms:bind id="name" nodeset="nodeset" property1 ... propertyn/>
Table 1. xformsmodels parameters
Parameter Type Description
name string Optional. An arbitrary name that you assign to the bind. All names assigned to id attributes must be globally unique within the form.
nodeset XPath An XPath expression that specifies which node or nodes in the data model are affected. This links the properties to one or more elements in a data instance.
property expression The property to apply to the indicated nodeset. Property attributes are expressed as follows: property_name = setting

Available Properties

The following list describes the properties you can set for a nodeset:

calculate
Applies a calculation that sets the content of a node. This calculation is written as an XPath expression that is evaluated relative to a node in the bind's nodeset.

For example, if you had a purchase order form, you might use the following expression to set the value of the “total” node to equal the value of the "subtotal" node plus the value of the “tax” node:

   calculate="../subtotal + ../tax"

Do not link a data node with a calculation to a UI element that has a value set by a an XFDL compute. When the XForms UI binding transfers data to the UI element, the XFDL compute is destroyed.

constraint
Allows you to set a constraint for a node. For example, you could specify that the value of the node must be greater than one, or that it must not equal the value of a different node.

This property is set by any XPath expression that results in a Boolean value. True means the constraint has been met, false means it has not.

For example, the following expression would ensure that the value for the upperPage node was always greater than or equal to the value of the lowerPage node:

   nodeset="pagination/upperPage"
   constraint=". &gt;= ../lowerPage"

If a constraint is set for a data node, and a different constraint is set for a linked UI element, then the validity of the data is determined by considering both settings. If the data is invalid for either setting, the data will be considered invalid overall.

If a node is relevant (see the following) and has a failed constraint, then an XForms submission is not permitted.

readonly
Sets whether the associated node is readonly. If a UI element is linked to a readonly node, then the UI element will also be readonly. However, if the UI element has the readonly option set, it will override the setting for the data node.

This property is set by any XPath expression that results in a Boolean value. True means the node is readonly, false means the node is not.

For example, the following expression would make the associated node readonly:

   readonly="true()"
relevant
Determines whether a node is relevant. Non-relevant nodes are omitted from XForms submissions. Additionally, if a UI element is linked to a non-relevant node, then that UI element is not displayed to the user. However, if the UI element has either the active or visible options set, they will override the setting for the data node.

This property is set by any XPath expression that results in a Boolean value. True means the node is relevant, false means the node is not.

For example, the following expression would make the node relevant if another node named “paymentType” had a value of “credit”:

   nodeset="creditCardNumber"
   relevant="../paymentType = 'credit'"
required
Sets whether the node requires input. If a UI element is linked to a required node, then the UI element inherits the setting. Furthermore, if the node does not require input, but a linked UI element does, then input is still required.

This property is set by any XPath expression that results in a Boolean value. True means the node is required, false means the node is not.

For example, the following expression would set the node to require input:

   required="true()"

If a relevant (see the previous) data node is required but empty, then an XForms submission in not permitted.

type
Sets the data type of the node. The valid data types are defined by XML schema.

For example, the following expression sets the node to a date type:

   type="xsd:date"

If the data type set for the node conflicts with the data type set for a linked UI element, then the validity of the data is determined by considering both settings. If the data is invalid for either setting, the data will be considered invalid overall.

For example, if you set a data node to be type int and you set a linked XFDL field to be type string, then typing in "abc" (a valid XFDL string) would still result in an error, since it does not match the int type.

If a relevant (see the previous) data node's content does not match its type, then an XForms submission is not permitted.

Available in

xforms:model

Example

This example shows a small XForms data model that contains the name, age, and birth date of a person. The model includes a bind that sets the datatype of <age> to xsd:integer and a bind that sets the datatype of <birthdate> to xsd:date.

<?xml version="1.0"?>
<XFDL xmlns="http://www.ibm.com/xmlns/prod/XFDL/8.0"
  xmlns:xfdl="http://www.ibm.com/xmlns/prod/XFDL/8.0"
  xmlns:xforms="http://www.w3.org/2002/xforms">
  <globalpage sid="global">
     <global sid="global">
        <xformsmodels xmlns="">
           <xforms:model>
              <xforms:instance>
                 <person>
                    <name></name>
                    <age></age>
                    <birthdate></birthdate>
                 </person>
              </xforms:instance>
              <xforms:bind nodeset="age" type="xsd:integer"/>
              <xforms:bind nodeset="birthdate" type="xsd:date"/>
              <xforms:submission id="submitTest" method="post"
                 resource="http://www.example.com/cgi-bin/people"
                 includenamespaceprefixes=""/>
           </xforms:model>
        </xformsmodels>
     </global>
  </globalpage>

Usage details

  1. When writing the XPath expression for a constraint, you must express the less than and greater than symbols as character references (&lt; and &gt; respectively) or they will be confused with the opening and closing symbols for the tag.
  2. When writing an XPath expression that references an instance, you must express the single-quote symbols as character references ('') or the expression is not evaluated correctly. For example:
    <xforms:bind nodeset="instance('Generated')/page1/field1"
    calculate="concat('instance('Generated')/page1/field1','')"/>