0

I need to retrieving the last matching element in xml using xpath. For Eg

<step >
 <step1 name="a">
    <calculation value="123.5">
 </step1>
 <step1 name="b">
    <calculation value="129.5">
 </step1>
<step1 name="a">
    <calculation value="124">
</step1>
<step1 name="c">
    <calculation value="130">
 </step1>
</step>

I want to retrieve the last matching value having name "a" which is 124 here.Can anyone please help.

kavin raj
  • 13
  • 2

1 Answers1

1

As in Stefans link, use last():

 /step/step1[@name="a"][last()]/calculation/@value

if you have an xml parser that can handle the file

BeniBela
  • 16,412
  • 4
  • 45
  • 52