Is it possible to get an absolute xpath given the relative one of a dom node, using javascript?
The closest I have found refers to getting xpath for a node: Get Xpath from the org.w3c.dom.Node
Moreover, I get relative xpaths for nodes without unique identifiers. Any ideas how to work around this?
For example, for:
<p>DUKE SOLINUS</p>
<div>
<p>AEGEON</p>
</div>
and for selected words "DUKE", and "AEGEON", I get xpaths "/p[1]", AND "/div[1]/p[1]" respectively, which when passed to document.evaluate function both evaluate to the same node "DUKE SOLINUS". So, I only have these relative xpaths, and do not have nodes. What I want is to evaluate these relative xpaths to correct nodes i.e. the two different nodes in this case (DUKE SOLINUS and AEGEON).
To be more specific, xpaths are taken from json annotation object: http://docs.annotatorjs.org/en/v1.2.x/annotation-format.html
Any help would be appreciated! Thanks a lot!