Sebix
Sebix

Reputation: 41

XPath : select only element when a value is lower than another in the same node

i got a problem with my XPath. I need to select for WP ALL IMPORT only values that are lower than another value in the same node. In this case i need select nodes where values in search_price are lowests than rrp_price. I read every things on stackoverflow but nothing corresponds to this case. Can you help me ? I m scratching my head with operators but i can t find the good way. Thank you

My XPath base is /product

Example for one product :

<product> <rrp_price> 192.90 </rrp_price> <search_price> 172.90 </search_price> </product>

Upvotes: 1

Views: 412

Answers (1)

Jack Fleeting
Jack Fleeting

Reputation: 24930

Depending on the exact structure of your xml, this xpath expression

//product[./search_price < ./rrp_price]

(or something similar) should get you all the product nodes which have a search_price child with a value which is lower than that of the value in the rrp_price node child.

Edit: translated into "plain English" the expression means: select any node (//) with the name of product, which has ([ and later ]) a child (./) called search_price, which child has a value (note that xpath silently assumes in this case that when you refer to the child, you refer to its numerical value; if that's not the case, more explicit instructions need to be issued) which is lower (<) than the value (same silent treatment) of another child of product with the name rrp_price.

Upvotes: 1

Related Questions