Chapter 4 explained how to construct match patterns, which you use with the match attribute of elements such as <xsl:template> . Those patterns are a subset of the full XPath language, and this chapter explores the full version of XPath.
XSLT actually has many more places to use XPath expressions than match patternsyou can use XPath expressions in the select attribute of the <xsl:apply-templates> , <xsl:value-of> , <xsl:for-each> , <xsl:param> , <xsl:variable> , <xsl: with-param > , <xsl:copy-of> , and <xsl: sort > elements, in attribute value templates, in the test attribute of <xsl:if> and <xsl:when> elements, the value attribute of <xsl:number> , and in the predicate of match patterns. Theres no getting around it: you dont know XSLT unless you know XPath, and this chapter is all about using and creating XPath expressions.
In fact, youve been dealing with XPath expressions since Chapter 1, when you first saw the select attribute in <xsl:apply-templates> and <xsl:value-of> :
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/PLANETS"> <HTML> <HEAD> <TITLE> The Planets Table </TITLE> </HEAD> <BODY> <H1> The Planets Table </H1> <TABLE BORDER="2"> <TR> <TD>Name</TD> <TD>Mass</TD> <TD>Radius</TD> <TD>Day</TD> </TR> <xsl:apply-templates/> </TABLE> </BODY> </HTML> </xsl:template> <xsl:template match="PLANET"> <TR> <TD><xsl:value-of select="NAME"/></TD> <TD><xsl:apply-templates select="MASS"/></TD> <TD><xsl:apply-templates select="RADIUS"/></TD> <TD><xsl:apply-templates select="DAY"/></TD> </TR> </xsl:template> <xsl:template match="MASS"> <xsl:value-of select="."/> <xsl:text> </xsl:text> <xsl:value-of select="@UNITS"/> </xsl:template> <xsl:template match="RADIUS"> <xsl:value-of select="."/> <xsl:text> </xsl:text> <xsl:value-of select="@UNITS"/> </xsl:template> <xsl:template match="DAY"> <xsl:value-of select="."/> <xsl:text> </xsl:text> <xsl:value-of select="@UNITS"/> </xsl:template> </xsl:stylesheet>