XPath: Seeking Out Your Data
XPath is the spy or seeker of the X-Team who is charged with going into an
XML document and picking out the requested information for XSLT. Without
the ability to precisely locate information in an XML document, the ability to
transform or do anything special with XML is minimal.
Any XSLT transformation must be set up to answer two questions:
Input: What information from the original XML document do you want?
Output: How would you like that information structured in the output
XSLT relies on XPath to answer the first question, as shown in Figure 1-4.
XSLT looks at an XML document element by element, so XPath expressions
are used to tell what your XSLT stylesheet should look for as it goes through
the XML document. Looking closer at the preceding XSLT example, the XPath
expression name tells XSLT what information to look for, which in this case is
to look for all name elements.
This XPath expression is intuitive and easy to understand, but for more hearty
needs, the syntax can be quite arcane and challenging. (I discuss XPath in
detail in Chapter 5.)
Interestingly, much of the effort required to develop XSLT stylesheets is
related to the input side of the equation, so throughout this book, I spend a
sizeable amount of time on how to use XPath.
Parts of an
What info do
you want from
you like the
Part I: Getting Started with XSLT