|Chapter 5 - XPath Espresso|
|XSLT For Dummies|
|by Richard Wagner|
|Hungry Minds 2002|
The centerpiece of the location step is the node test . The axis is given a value if you dont define one, and the predicate is optional. The node test, however, must be part of every single location step you create. The node test looks at the node set given to it by the axis and says, I want the nodes with this name or this type.
The most common node tests look for a match based on an element name. For example, the following XSLT snippet was used earlier in the chapter to return the chapter titles to the output tree:
<xsl:template match="title"> <xsl:apply-templates/> </xsl:template>
This node test, which should look fairly commonplace to you by now, says, I want all the title elements from the node set given to me by the child axis."
In addition to using element names as the node test, you can also use several other node tests, as shown in Table 5-2.
Given that there are multiple types of nodes, you may be wondering how the processor knows that title from the preceding match pattern is referring to an element node rather than some other type. The reason is that every axis has a principal node typ e (or default node type). Most of the axes have a principal node type of an element, but there are a couple of exceptions: attribute axis has a principal node type of attribute and namespace axis has a principal node type of namespace. So, in the preceding example, because child the implicit axis for title has a principal node type of element, the processor knows that the match pattern is referring to an element node named title .