Relative links

In all previous examples, the origin of the XPath expression is the root of the document. XPointer adds two kinds of 'relative context' to allow an external or internal starting point to be specified instead.

Local context

Relative linking is possible using the here() function at the beginning of the expression. There are two possible interpretations of what 'here' actually means, though they are similar.

In the first scenario, the XPointer expression is the text content of an element. In this case, 'here' refers to the enclosing element node. In the following example, it refers to the Link element, so the expression can target the previous Paragraph element using the previous-sibling() axis:

 <para>The link below targets this ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.