W3C home > Mailing lists > Public > public-annotation@w3.org > November 2015

Re: [web-annotation] XPath Range Selector

From: Randall Leeds via GitHub <sysbot+gh@w3.org>
Date: Wed, 04 Nov 2015 21:45:57 +0000
To: public-annotation@w3.org
Message-ID: <issue_comment.created-153876212-1446673555-sysbot+gh@w3.org>
What I was missing was the `string` function and the fact that the 
string-value of an element includes the concatenation of the 
string-value of each of its children.

Using a construction like `string(/html/body/article/p[1])` would 
fulfill my use case.

So, for instance, the range that encompasses the text between the 10th
 character of the first paragraph and the 8th character of the third 
paragraph, each of the article:

  "type": "XPathRangeSelector",
  "startPath": "substring(string(//article/p[1]), 10)",
  "endPath": "substring(string(//article/p[3]), 0, 8)"

The only problem with this in practice for DOM selections is that the 
path expressions would have to be tokenized manually first since the 
standard XPath APIs would give you a string result for each of these.

For example, to process this example for the use case of highlighting 
the resulting range, one would need to write code to parse out the 
`//article/p[n]` references and the substring function offsets, use 
the DOM XPath APIs to look up the node references and then iterate 
text nodes to find the container/offset suitable for constructing a 
DOM `Range`.

That's doable, but the first step could be avoided if the startPath 
and endPath are each selectors that point to a node with sub-selectors
 that specify the text offsets within. It avoids the need to tokenize 
the paths.

I could live with it, though.

GitHub Notif of comment by tilgovi
Received on Wednesday, 4 November 2015 21:45:59 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:54:42 UTC