XPath axe
following:: axis
Every node after the context node's closing tag, across the rest of the document rather than only among its siblings.
following:: selects nodes that begin after the context node ends. Unlike following-sibling:: it crosses parent boundaries, so it can reach descendants of later siblings and anything later in the document.
It does not include descendants of the context node: those begin before its closing tag. That boundary is the difference between following:: and a loose reading of 'everything later'.
- Syntax
following::name- Returns
- node-set
- Kind
- Axe
- Version
- XPath 1.0 (libxml2)
Worked examples
Each result below is what the evaluator returned, asserted on every test run. An empty result means an empty node-set — which is an answer, not an error.
count(/order/customer/following::price)on order.xmlRun3All three price elements begin after <customer> ends.
/order/customer/following::line[1]/@skuon order.xmlRunsku="WIDGET-1"count(/order/lines/following::price)on order.xmlRun0The prices are descendants of <lines>, not nodes following its closing tag.
What catches people out
- following:: crosses parent boundaries; following-sibling:: stays under one parent and is usually the safer expression.
- Descendants are excluded even though they appear later than the start tag in the source.
- The axis can scan most of a large document. Anchor it to a narrow context before using it.
The sample documents
Every example on this page runs against this document. The sitemap one is namespaced on purpose — almost every real XML document is, and that changes which expressions match.
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1001" tier="gold">
<customer country="NO">Ada Lovelace</customer>
<!-- priority customer -->
<?audit retained?>
<lines>
<line sku="WIDGET-1" qty="2"><price>14.50</price></line>
<line sku="WIDGET-2" qty="1"><price>39.00</price></line>
<line sku="GIFT-WRAP" qty="1"><price>0.00</price></line>
</lines>
<note> Deliver after 09:00 </note>
</order>Related
- following-sibling:: and preceding-sibling::Siblings after (or before) the context node. preceding-sibling:: is a reverse axis, which changes what [1] means.
- preceding:: axisEvery node before the context node's opening tag, excluding its ancestors. A reverse axis, so [1] means nearest.
- descendant:: and descendant-or-self::Everything below a node, at any depth. // is shorthand for descendant-or-self, which is why //a//b can be expensive.
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.