XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath: getting started / Getting started with XPath: path expressions / Found: the path expression’s result

(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, chapter 1.)

A path expression is better understood as a condition that may match a set of potential target nodes relative to a reference node, rather than as a rigid relationship between one start and one target node.

Suppose there were several elements <gruss> satisfying path condition hallo/gruss rather than just one. Which would be selected?

Simply: all of them.

<?xml version="1.0" encoding="ISO-8859-1"?>
<hallo>
  <gruss>Hallo Welt! Dies ist XSLT.</gruss>
  <gruss>Salve!</gruss>
  <gruss>Tag zusammen!</gruss>
</hallo>

Code example: kap01/1.11.5/hallo.xml.

Here, /hallo/gruss would select all three elements <gruss> inside hallo. The path expression is said to be inclusive (inclusive), since it includes all matching nodes.

Do not be misled by this example’s simplicity. The selected nodes need not be adjacent, close together or at a single hierarchy level: they may be scattered anywhere in the document tree.

The selection forms a sequence. Its nodes occur in the same order as in the document, called document order. This also determines the order in which the sequence members, generally called items, are subsequently processed.

Set in XSLT 1.0 versus sequence in XSLT 2.0
XPath 1.0 calls the selection an inherently unordered collection or set. XPath 2.0 emphasizes its order and calls it a sequence, even when only one node, or none, is selected.

The term “item” indicates that a sequence can contain more than node representations. If it contains only nodes, it may also be called a node sequence, analogous to XPath 1.0’s node set.

Summary of path expressions:

  • A path expression inside a template rule refers to its context: the currently processed node matched by the pattern of the match attribute.

  • A relative path expression’s meaning depends on its reference point, or context.

  • An absolute path starts with / and always begins at the document node, one level above the root element.

  • A path contains one or more location steps, separated from one another by slashes.

  • A path expression applies inclusively to every matching part of the document. The selected parts form an ordered sequence that also determines processing order.

   

back to top