For unstructured links, you might try something like //body/descendant::a[text()='a link'][9]
. The descendant axis will flatten all the descendant 'a' tags so position() will take the order they appear in the document rather than being based on the previous siblings of each a tag.
If the links are semi-structured as below, then something like
//div[@id='fu']//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']/../following-sibling::*//a[text()='a link']
can find you the 9th matching link with the given structure.
<p>a segment, outside the containing div, with <a href="www.google.com">a link</a>.</p>
<div id="fu">
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a different link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<p>some text <a href="www.google.com">a link</a>.</p>
<div></div></div>