Navigating Along the following Axis

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XPath Developer's Guide

Navigating Along the following Axis

All nodes that follow the context node, in document order, lie along the following:: axis. This specifically excludes attribute and namespace nodes, as well as nodes that are descendants of the context node.

Given the sample XML document of Lucerne Publishing's organization chart, you could locate, all employees that follow the employee named Katie McAskill-White with the XSLT template rule shown below.

Because the context node established by the template rule's match pattern is the <name> element whose string value is Katie McAskill-White (match="name[.='Katie McAskill-White']"), the <xsl:for-each> element's select pattern, "following::*/name", locates the names of all employees that follow the context node, in document order.

Example

XML File (orgchart.xml)

Use orgchart.xml (in Sample XML File for Navigating XPath Axes) and edit its href attribute to refer to orgchart-follow.xsl.

XSLT File (orgchart-follow.xsl)

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- suppress text nodes not covered in subsequent template rule -->
<xsl:template match="text()"/>

<xsl:template match="name[.='Katie McAskill-White']">
    <h2>Katie McAskill-White's followers:</h2>
        <xsl:for-each select="following::*/name">
            <h4><xsl:value-of select="."/></h4>
        </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Formatted Output