The range() function is great for times when you need to define a range which begins and ends with the same element. However, for situations which require more asymmetric ranges, XPointer also offers the range-to() function, which allows link authors greater flexibility when defining ranges. The range-to() function creates a range beginning with the context node and ending with the location set specified as an argument to the range-to() function. For example, the following XPointer defines a range beginning at the opening "cast" element and ending at the closing "director" element. It's also possible to identify points and ranges within character data - the string-range() function scans a specified location for a match to a user-specified string, and returns a range containing the result. So, the following XPointer would return a range enclosing the string "Patrick Stewart" from the "cast" element. If the XML document above contained more than one "cast" element matching the specified string, the string-range() function would return multiple ranges, one for each match. It's possible to further constrain the range returned by specifying two additional arguments to the string-range() function - an offset to push forward the starting point of the range, and a length constraint to move back the ending point. So a modification of the XPointer above to would return a range enclosing the substring "Stew". The string-range() function ignores embedded elements - which means that a change to the XML document above to read would not affect the XPointer at all. Since the string-range() function only returns string ranges, it follows that the start and end points of these returned ranges are always character-points, not node-points.
blog comments powered by Disqus |