Sebastian Amenabar
Sebastian Amenabar

Reputation: 91

Mathematical operation with XML node values for selection

I'm trying to use the value of an XML node to select a group of nodes, my specific problem is the following. I have the nodes computers with the attribute model and in their children is the node HardDrive

<PC model="Lindows OSX">
    <HardDrive>500</HardDrive>
</PC>

I'd like to select only the PCs which HardDrive is over 500gb, so I dont know if the function text() let's me work with numbers, something like

//parent::HardDrive[text()>500]/@model

Upvotes: 1

Views: 52

Answers (2)

Yeldar Kurmangaliyev
Yeldar Kurmangaliyev

Reputation: 34189

You can use the following XPath:

root/PC[HardDrive[. > 500]]/@model

It will extract all model names of PCs with hard drive capacity > 500.

Demo at xpathtester.com.

Upvotes: 1

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

[text()>500] is a valid XPath condition. That's what you want I reckon:

//PC[HardDrive > 500]/@model

Upvotes: 2

Related Questions