Here is the xml I am working with and I am trying to the the id number of the first different pd value I encountered.
<result>
<pd>a</pd>
<id>1</id>
<pd>a</pd>
<id>2</id>
<pd>b</pd>
<id>8</id>
<pd>c</pd>
<id>9</id>
<pd>c</pd>
<id>4</id>
<pd>d</pd>
<id>7</id>
</result>
so the result that I am expecting is:
<pd>a</pd>
<id>1</id>
<pd>b</pd>
<id>8</id>
<pd>c</pd>
<id>9</id>
<pd>d</pd>
<id>7</id>
I used following-sibling::*[2] to get to the next pd and compare that with the current node but then it only gave me b, not c and d. Can any of you give me a hint on how to iterate through the whole xml to get the desired output? Thanks!!
There may be more elegant solutions, but the strategy I took was to gather all of the distinct values in the pd elements, then loop through all of the pd elements and grab the first sibling where the value in the pd element matched the value in the current iteration of the distinct values.
For your code, this yields