I want to select the first
product in the following XML with
name 'bread'
At first I was thinking that this would work:
/SHOP/BASKET/PRODUCT[NAME='bread'][1]
However, this selects the first bread product
for each basket
I only want to select the first bread product that appears in the document. I can return this by using:
/SHOP/BASKET[PRODUCT/NAME='bread'][1]/PRODUCT[NAME='bread'][1]
Fair enough but I imagine there is a more succinct solution. Much obliged if anyone can help.
Cheers
EDIT: This also works, though I believe the above method is more efficient:
/SHOP/descendant::PRODUCT[NAME='bread'][1]
Anyone know a more efficent method?
<?xml version="1.0" encoding="UTF-8"?>
<SHOP>
<BASKET colour="black">
<PRODUCT>
<NAME>beans</NAME>
<VAL>BAKED</VAL>
</PRODUCT>
</BASKET>
<BASKET colour="green">
<PRODUCT>
<NAME>bread</NAME>
<VAL>BROWN</VAL>
</PRODUCT>
<PRODUCT>
<NAME>bread</NAME>
<VAL>WHITE</VAL>
</PRODUCT>
</BASKET>
<BASKET colour="blue">
<PRODUCT>
<NAME>pasta</NAME>
<VAL>MAC</VAL>
</PRODUCT>
<PRODUCT>
<NAME>bread</NAME>
<VAL>TOASTED</VAL>
</PRODUCT>
</BASKET>
</SHOP>