|Attaches properties and constraints to a nodeset in the model.
Table 1. xformsmodels parameters
<xforms:bind id="name" nodeset="nodeset" property1 ... propertyn/>
|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 |
The following list describes the properties you can set for a nodeset:
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:
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.
calculate="../subtotal + ../tax"
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:
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 below) and has a failed constraint, then an XForms submission is not permitted.
constraint=". >= ../lowerPage"
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:
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”:
relevant="../paymentType = 'credit'"
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:
If a relevant (see above) 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:
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 above) data node's content does not match its type, then an XForms submission is not permitted.
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.
<xforms:bind nodeset="age" type="xsd:integer"/>
<xforms:bind nodeset="birthdate" type="xsd:date"/>
<xforms:submission id="submitTest" method="post"
- When writing the XPath expression for a constraint, you must express the less than and greater than symbols as character references (< and > respectively) or they will be confused with the opening and closing symbols for the tag.
- When writing an XPath expression that references an instance, you must express the single-quote symbols as character references (") or the expression will not be evaluated correctly. For example: