使用Xpath选择特定的非空节点

时间:2014-04-09 14:47:16

标签: php xpath

我有两个Xpath请求:

$was_price_location = "//ul[@id='items']/li/div[@class='productprice']/span[@class='price' or @class='recRP rrp']";
$now_price_location = "//ul[@id='items']/li/div[@class='productprice']/span[@class='prevPrice previousprice' or @class='price outlet-current-price']";

但是,我想修改它,以便只返回指定为空的节点。

目前,它发现多余的<span class="recRP rrp"><span class="prevPrice previousprice">个节点是空的,因此与我无关。

1 个答案:

答案 0 :(得分:0)

这应该有效:

$prod_price_location = "//ul[@id='items']/li/div[@class='productprice']";
$was_price_location = $prod_price_location . 
    "/span[@class='price' or @class='recRP rrp'][normalize-space()]";
$now_price_location = $prod_price_location . 
    "/span[@class='prevPrice previousprice' or @class='price outlet-current-price']" .
    "[normalize-space()]";