/ul[2]...
should return the first post of the second ul
Assuming that the number of posts per ul
is both variable, and also not important (i.e. you want the posts irrespective of which ul
they are in), then you can bypass the ul
.
If <li class='notification-posted'>
uniquely identifies posts, you can reference the 3 links as follows:
(//li[@class='notification-posted'])[1]/a[2]
(//li[@class='notification-posted'])[2]/a[2]
(//li[@class='notification-posted'])[3]/a[2]
(// ... )[n]/a[2]
The a[2]
is needed because you are after the second link in each instance.
If this isn't selective enough, you can add the filter that the li
must also contain an img
of notification-posted.png
icon is always associated with the hyperlink:
(//li[@class='notification-posted'][img src="/assets/images/icons/notification-posted.png"])[1]//a[2]
and the same for links [2]
and [3]
Edit
You can find all links which have the text post
with the following xpath:
//a[@href][normalize-space(.)='post']
Tested on the (xhtml
ized version of your html) with the following xsl:
<xsl:for-each select="//a[@href][normalize-space(.)='post']">
<Link>
<xsl:value-of select="@href"/>
</Link>
</xsl:for-each>
Gives:
<Link>/news/53235</Link>
<Link>/news/253129-loss</Link>
<Link>/news/25151-helloworld</Link>