Reputation: 35
<?xml version="1.0" encoding="UTF-8"?>
<sensor-system>
<velocity>120.00</velocity> <!-- km/h -->
<temperature location="inside">24.6</temperature>
<temperature location="outside">-12.5</temperature>
<seats>
<seat location="front">
<id>1</id>
<temperature>32.5</temperature>
<heating-is-on/>
</seat>
<seat location="back">
<id>2</id>
<temperature>23.5</temperature>
</seat>
</seats>
</sensor-system>
Give an absolute XPATH that identifies all front seats with a temperature greater than or equal to 20.0 and less than or equal to 30.0 degrees celsius.
Is this correct :
/sensor-system/seats[temperature>=20 | temperature <=30]/seat[@location="front"]
Thank you.
Upvotes: 0
Views: 79
Reputation: 70598
You xpath is not quite correct because it is expecting the temperature element to be a child of the seats element, when you should be checking the seat element.
EDIT: Another thing to point out that in your original xpath, you are using the '|' operator, which is the union operator, and which takes two node-sets as arguments. So it won't work in your example, as your arguments are actually 'conditions'.
Try this instead
/sensor-system/seats/seat[temperature >= 20][temperature <= 30][@location = "front"]
Note, if you were using this in XSLT, you might have to escape the < here
/sensor-system/seats/seat[temperature >= 20][temperature <= 30][@location = "front"]
Although you may prefer to do this
/sensor-system/seats/seat[temperature >= 20][not(temperature > 30)][@location = "front"]
Upvotes: 3
Reputation: 184955
Try doing this :
/sensor-system/seats/seat[@location="front"]/temperature >=20 and /sensor-system/seats/seat[@location="front"]/temperature <= 30
This will be true
for [@location="back"]
and false
for [@location="front"]
Upvotes: -1