Skip to main content
XMLDir

Search 169 pages — formats, namespaces, parser messages, schema errors and tools.

XPath axe

self:: axis

The context node itself. Abbreviated as a dot, and used to test what the current node is.

self:: selects the context node, which sounds useless until you use it as a test: self::line is true only when the context node is a <line>. That makes it the way to filter a mixed node-set by name.

The abbreviation . is the same axis with a node() test, and is what you compare against inside a predicate: [. > 20] tests the context node's value.

Syntax
self::name — or .
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(//price[. > 20])on order.xmlRun
    1
  • count(//lines/*[self::line])on order.xmlRun
    3

    Filtering a wildcard by node name.

  • normalize-space(//note/.)on order.xmlRun
    Deliver after 09:00

Run your own expression

What catches people out

  • . is the context node, not the context node's string — though it converts to one in a comparison.
  • .// and // are different: the first is relative, the second restarts at the document root.

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>
  <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 34 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.