xpath - 如果value小于其他值

时间:2013-08-22 03:24:00

标签: xml xpath

我使用<price><newprice>作为两个值的XML Feed 我需要的是xpath函数,只有当它的值小于旧<newprice>时才显示<price>。如果值不小,则不显示任何内容(或0也可以)。

示例:

<price>88</price><newprice>88</newprice>结果为'0' <price>88</price><newprice>45</newprice>结果为'45'

一般来说,我希望新价格只有在价值较小时才可见。否则应显示为“0”。感谢

1 个答案:

答案 0 :(得分:0)

输入

<?xml version="1.0" encoding="UTF-8"?>
<prices>
    <price>88</price>
    <newprice>88</newprice>
</prices>

在xpath 1.0中,这可行(如果新价格不低则不返回)

/prices/newprice[number(.) &lt; number(preceding-sibling::price)]

在xpath 2.0中,这可以完成(返回零)

if (prices/newprice &lt; prices/price) then prices/newprice else 0 
相关问题