Chapter 3. Location Steps and Paths
In Chapter 2, I covered the kinds of content XPath is capable of locating: essentially, any content at all in an XML document. Now it’s time to take a look at how exactly you locate it — a look, in short, at XPath syntax.
XPath Expressions
As earlier chapters (notably Chapter 1) have explained, knowing XML’s own syntax does not prepare you for knowing XPath syntax. Unlike the languages that make use of XPath, XPath itself is not an XML vocabulary. A given “XPath” doesn’t contain all the characteristic left and right angle brackets, ampersands, and other hallmarks of XML syntax dear (or not) to your heart from your other XML work.
Instead, units of XPath meaning, called expressions, are typically used in attribute values. Thus you’ll be creating and using XML code that uses these expressions in ways such as:
<xsl:value-of select="expression
"/>
and:
<a xlink:href="xpointer(expression
)">Table of Contents</a>
Sometimes, when you see the term XPath expression, what’s being referred to is simply a speck of meaning — a subatomic particle, as it were, that has a sort of abstract academic interest but little practical value by itself. This sort of expression is a string or numeric value. For instance, both of the following are valid XPath expressions in this limited sense:
"I should have been a pair of ragged claws" 119.725
In the real world of XPath, though, such literal expressions are pretty pointless. If you locate the literal string “I should have been ...
Get XPath and XPointer 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.