These full, unabbreviated location paths may be absolute if they
start from the root node, just as abbreviated paths can be. For
example, the full form
/child::people/child::person is equivalent to the
abbreviated form /people/person.
Unabbreviated location paths may have and be used in predicates as
well. For example, the abbreviated path
/people/person[@born<1950]/name[first_name="Alan"]
becomes /child::people/child::person[ attribute::born <
1950 ] /child::name[ child::first_name = "Alan"
] in the full form.
Example 9-4. An XSLT stylesheet that uses unabbreviated XPath syntax
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<dl>
<xsl:apply-templates select="descendant::person"/>
</dl>
</xsl:template>
<xsl:template match="person">
<dt><xsl:value-of select="child::name"/></dt>
<dd>
<ul>
<xsl:apply-templates select="child::name/following-sibling::*"/>
</ul>
</dd>
</xsl:template>
<xsl:template match="*">
<li><xsl:value-of select="self::*"/></li>
</xsl:template>
<xsl:template match="homepage"
xmlns:xlink="http://www.w3.org/1999/xlink">
<li><xsl:value-of select="attribute::xlink:href"/></li>
</xsl:template>
</xsl:stylesheet>
The first template rule matches the root node. It applies templates
to all descendants of the root node that happen to be
person elements. That is, it moves from the root
node along the descendant axis with a node test of
person. This XPath expression could have been
rewritten in the abbreviated syntax as //person.
The second template rule matches person elements.
It places the value of the name child of each
person element in a dt element.
The location path used here, child::name, could
have been rewritten in the abbreviated syntax as the single word
name. Then it applies templates to all elements
that follow the name element at the same level of
the hierarchy. It begins at the context node
person element, then moves along the child axis to
find the name element. From there it moves along
the following-sibling axis looking for elements of
any type (*) after the name
element that are also children of the same person
element. There is no abbreviated equivalent for the
following-sibling axis, so this really is the
simplest way to make this statement.
The third template rule matches any element not matched by another
template rule. It simply wraps that element in an
li element. The XPath self::*
selects the value of the currently matched element, that is, the
context node. This expression could have been abbreviated as a single
period.