Skip to main content

Search 400 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, guides, blog and product.

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.xmlRun
    3

    All three price elements begin after <customer> ends.

  • /order/customer/following::line[1]/@skuon order.xmlRun
     sku="WIDGET-1"
  • count(/order/lines/following::price)on order.xmlRun
    0

    The prices are descendants of <lines>, not nodes following its closing tag.

Run your own expression

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.

order.xml
<?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

All 40 XPath entries

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.