How do I select the last XHTML <span> element with a particular class in XPath?
- by Fintan
My target XHTML document (simplified) is like the following:
<html>
<head>
</head>
<body>
<span class="boris"> </span>
<span class="boris"> </span>
<span class="johnson"> </span>
</body>
</html>
I'm trying to select the last of class "boris."
The XPath expression
//span[@class="boris"]
selects all spans of class boris. How do I select the last one of these?
I've tried
//span[@class="boris" and last()]
which doesn't work because last() here refers to the last span in the WHOLE DOCUMENT.
How do I select all the spans of class boris... and then the last one of these?
I've read 5 or 6 XPath tutorials and done a lot of Googling and I can't find a way to do this in XPath alone :(
Thanks in advance for help :)