Chapter 2. The XPath Language

XPath 1.0 is the expression language embedded in XSLT 1.0. This chapter lists the primitives of XPath, including its four data types and how expressions of each type are evaluated.

Data Types

An XPath expression returns a value that has one of the following four data types:

  • Node-set (an unordered collection of zero or more nodes without duplicates)

  • Number (a floating-point number)

  • String (a sequence of Unicode characters)

  • Boolean (true or false)

Result Tree Fragments

XSLT adds one more data type to this list, the result tree fragment, which is created when an xsl:variable or xsl:param instruction uses content rather than the select attribute to define a variable. For example, given the following instruction, the value of $var will be a result tree fragment:

<xsl:variable name="var">
  <foo>text</foo>
  <bar/>
</xsl:variable>

A result tree fragment behaves like a node-set that contains one root node, except that certain operations allowed on node-sets are forbidden on result tree fragments. Result tree fragments can be converted to strings and copied to the result tree like regular node-sets, but the /, //, and [] operators are disallowed. Thus, the expression $var/foo is illegal. The only way to select the above foo element in XSLT 1.0 is to use an extension function that first converts the result tree fragment to a node-set, as in exsl:node-set($var)/foo. See Chapter 6.

Tip

XSLT 2.0 removes this restriction, abolishing the data type “result tree fragment” altogether. ...

Get XSLT 1.0 Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.