How XPath is Used in XForms

Given a good understanding of what XPath is and how it works, it’s pretty simple to see how it fits into the XForms architecture.

Context Nodes

Every use of XPath in XForms involves a context node, usually with the effect of shortening the number of steps needed in the path expression. For example, if the instance data is a simple XHTML document:

<html:html xmlns:html="">
    <html:title>Mutant Registration Guidelines</html:title>
    <html:p>The White House announced today...</html:p>

the default context node is the element node named html:html. Thus, to bind a form control to the document title, instead of the longer absolute path /html:html/html:head/html:title, a shorter relative path html:head/html:title could be used. The key difference between the two is that absolute paths contain a leading slash and the name of the root element. Since there can be only one root element, including its name in every path expressions isn’t necessary—path expressions don’t become ambiguous by leaving out what is really a redundant step along the path.

The default context node can be changed. Any element containing a binding expressions resets the context node for any child elements. Binding expressions include the ref attribute possibly with the model attribute, or alternatively the bind attribute. Either way, the expression selects a node-set from the instance data, and the first node, ...

Get XForms Essentials now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.