Chapter 1 - Introducing the X-Team | |
XSLT For Dummies | |
by Richard Wagner | |
Hungry Minds 2002 |
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:
XSLT relies on XPath to answer the first question, as shown in Figure 1-4. Figure 1-4: XSLT uses XPath to retrieve data from XML documents. 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. <xsl:template match="name"> <fullname> <xsl:apply-templates/> </fullname> </xsl:template> 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.
|