XPath: Seeking Out Your Data

 
xslt for dummies
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:

  • Input: What information from the original XML document do you want?

  • Output: How would you like that information structured in the output document?

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.

  
 
 
2000-2002    Feedback


XSLT For Dummies
XSLT for Dummies
ISBN: 0764536516
EAN: 2147483647
Year: 2002
Pages: 148

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net