I need to retrieve the index of specific nodes from an XML document. The task is similiar to the one here (Find position of a node using xpath), but I have trouble applying the suggested solutions to the "more than one requested child node" scenario. Consider the following example XML document
<a>
<b>zyx</b>
<b>wvu</b>
<b>tsr</b>
<b>wvu</b>
</a>
I want to retrieve the index for the b nodes with value "wvu" relative to a, i.e. I want to yield a vector [2,4]. Can this be done with XPath 1.0? Specifically I am using the XML package in R.
/Edit
Here is an Example document:
library(XML)
file1 <- htmlParse("<a><b>zyx</b><b>wvu</b><b>tsr</b><b>wvu</b></a> ")
xpathSApply(file1, "count(a/b[.='wvu']/preceding-sibling::*)+1")
[1] 1