Chapter 3. XPath in XForms

“Nobody trips over mountains. It is the small pebble that causes you to stumble. Pass all the pebbles in your path and you will find you have crossed the mountain.”

Traditional proverb

The most obvious difference between XForms and earlier technologies is the representation of form data as XML instead of flat name/value pairs. While a richer data representation was a welcome change, it also called for a more sophisticated language to reference structured data. The W3C had already defined just such a language, called XPath (, a component of XSLT (, an XML vocabulary used for transforming one flavor of XML into another. The XPath specification was built with the intention that later specifications could use it as a foundation, which is exactly what XForms does. This chapter first lays out the foundation of XPath, and then shows how XForms builds on that foundation.

What exactly is XPath? The “path” portion of the name comes from the similar appearance of many XPath expressions to directory paths in a filesystem, as shown in Example 3-1. XPath also includes some lightweight calculation functionality, such as basic mathematics, rounding, and string manipulation, which the calculation engine in XForms takes advantage of instead of defining a new (and incompatible) language.

Example 3-1. Some XPath expressions

/html/head/title html:head/xforms:model/@xml:id ../items purchaseOrder/items/item[3] purchaseOrder/items/item[@price ...

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.