60 likes | 201 Views
Is the cost of the 4 th juicer less than the cost of its following juicers?. Incorrect. //juicer[4]/number(cost ) < //juicer[4]/following-sibling::juicer/ number(cost ). The XPath gives the right answer for this data:. 82.00 < (234.00, 639.99) (82.00 < 234.00) or (82.00 < 639.99)
E N D
Is the cost of the 4th juicer less than the cost of its following juicers?
Incorrect //juicer[4]/number(cost ) < //juicer[4]/following-sibling::juicer/number(cost ) The XPath gives the right answer for this data: 82.00 < (234.00, 639.99) (82.00 < 234.00) or (82.00 < 639.99) T or T T But it gives the wrong answer for this data: 82.00 < (72.00, 639.99) (82.00 < 72.00) or (82.00 < 639.99) F or T T
Correct not(//juicer[4]/number(cost ) >= //juicer[4]/following-sibling::juicer/number(cost )) The XPath gives the right answer for this data: not(82.00 >= (234.00, 639.99)) not((82.00 >= 234.00) or (82.00 >= 639.99)) not(F or F) T And it gives the right answer for this data: not(82.00 >= (72.00, 639.99)) not((82.00 >= 72.00) or (82.00 >= 639.99)) not(T or F) F
Guideline for using general comparison operators • If you want to do general comparison of sequences, don’t do this: A positive-operator B • Instead, do this: not (A negative-operator B) • Example, don’t do this: A < BInstead, do this: not(A >= B) • Example, don’t do this: A = BInstead, do this: not(A != B) • Example, don’t do this: A >= BInstead, do this: not(A < B) Where A and/or B are sequences
Is 10 less than all the values in this sequence: (20, 30)? The overwhelming temptation is to write this XPath: 10 < (20, 30) The XPath works for this particular set of data, but change the data and it fails: 10 < (5, 30)Let’s see why: (10 < 5) or (10 < 30) F or T T Instead, use this XPath: not(10 >= (5, 30)) not((10 >= 5) or (10 >= 30)) not(F or T) F
Is 10 equal to all the values in this sequence: (10, 10)? The overwhelming temptation is to write this XPath: 10 = (10, 10) The XPath works for this particular set of data, but change the data and it fails: 10 = (5, 10)Let’s see why: (10 = 5) or (10 = 10) F or T T Instead, use this XPath: not(10 != (5, 10)) not((10 != 5) or (10 != 10)) not(T or F) F