The range-to( ) Function
The range-to( )
function is evaluated with respect to a context node.
It takes a location set as an argument that should return exactly
one location. The start-points of the context nodes are the
start-points of the ranges it returns. The end-point of the argument
is the end-point of the ranges. If the context node set contains
multiple nodes, then the range-to(
)
function returns multiple ranges.
Tip
This function is underspecified in the XPointer specification. In particular, it is not clear what should happen if the argument contains more or less than one location.
For instance, suppose you want to produce a single range that
covers everything between <title>
and </year>
in Example 11-1. XPointer does
this by starting with the start-point of the title
element and continuing to the
end-point of the year
element:
xpointer(//title/range-to(year))
Ranges do not necessarily have to cover well-formed fragments
of XML. For instance, the start-tag of an element can be included
but the end-tag left out. This XPointer selects <title>The Wonderful Wizard of
Oz
:
xpointer(//title/range-to(text( )))
It starts at the start-point of the title
element, but it finishes at the
end-point of the title
element’s
text node child, thereby omitting the end-tag.
Get XML in a Nutshell, 3rd 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.