XPath is another recommendation from the W3C and is designed for use by XSLT and another technology called XPointer. The primary goal of XPath is to define a mechanism for addressing portions of an XML document, which means it is used for locating element nodes, attribute nodes, text nodes, and anything else that can occur in an XML document. XPath treats these nodes as part of a tree structure rather than dealing with XML as a text string. XSLT also relies on the tree structure that XPath defines. In addition to addressing, XPath contains a set of functions to format text, convert to and from numbers, and deal with booleans.
Unlike XSLT, XPath itself is not expressed using XML syntax. A simplified syntax makes sense when you consider that XPath is most commonly used inside of attribute values within other XML documents. XPath includes both a verbose syntax and a set of abbreviations, which end up looking a lot like path names on a file system or web site.
XSLT uses XPath in three basic ways:
To select and match patterns in the
original XML data. Using XPath in this manner is the focus of this
chapter. You see this most often in
<xsl:template match="pattern"> and
<xsl:apply-templates select="node-set-expression"/>. In either case, XPath
syntax is used to locate various types of nodes.
To support conditional processing. We will see the exact syntax of
<xsl:choose> in the next chapter, both of which rely on XPath’s ability to represent ...