Search code examples
xmlxpathgoogle-sheets-formula

XPath relative vs absolute tests


I would like to better understand the meaning and usefulness of . before /h3. I looked for a website with a tutorial, but I couldn't find one explaining its use.

//div[./h3/a[text()='Home']]

Solution

  • The difference is that of relative vs absolute selection.

    Disregarding the /a[text()='Home'] common to both cases:

    • Relative selection: //div[./h3] selects all div elements that have an h3 child element.
      Note that it can be simplified to //div[h3].
    • Absolute selection: //div[/h3] selects all div elements provided that the document root element is h3.

    Absolute tests such as /h3 within a predicate ([/h3]) are relatively uncommon.

    See also