MLEN
MLEN

Reputation: 2561

Extracting elements with attributes using Xpath

In the following XM, how can I extract nodes, where the price is higher than 25 and currency, is "usd"?

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book>
  <title lang="eng">Harry Potter</title>
  <price currency = "usd">29.99</price>
</book>

<book>
  <title lang="eng">Learning XML</title>
  <price currency="gbp">39.95</price>
</book>

</bookstore>

Upvotes: 1

Views: 28

Answers (2)

kjhughes
kjhughes

Reputation: 111541

This XPath,

//book[price/@currency = "usd"][price > 25]

will select all books that cost more than $25 USD.

Upvotes: 1

MadRay
MadRay

Reputation: 441

If i understood Your task right, something like this can help You:

//book[./price[@currency='usd' and text()>25]]

Upvotes: 1

Related Questions