2012-12-15 222 views
0

我要排除此表中的IMG值:需要帮助:XPath查询

<table class="info"> 
<tbody> 
    <tr><th class="round-top" colspan="2">Status</th></tr> 
    <tr class="even"> 
    <td class="key">Schaltprogramm aktiv</td> 
    <td class="value"><img height="15" src="./pics/ste-symbol_an-97b765.png"></td> 
    </tr> 
</tbody> 
</table> 

我要排除此表中的值:

<table class="info"> 
<tbody> 
    <tr><th class="round-top" colspan="2">Warmwasser</th></tr> 
    <tr class="even"> 
    <td class="key">WW-Isttemp.</td> 
    <td class="value">49,0 °C</td> 
    </tr> 
    <tr class="odd"> 
    <td class="key round-leftbottom">WW-Solltemp.</td> 
    <td class="value round-rightbottom">46,5 °C</td> 
    </tr> 
</tbody></table> 

这里是我的不好的测试:

$nodelist = $xpath->query("//tr/td[substring(@class,1,5)='value']"); 
$imgs = $xpath->query("//table[@class='info']/tr/td/img"); 

我必须做些什么来排除变量“nodelist”中的IMG值?

有什么想法?

+0

XPath是XML文档的* query *语言。因此,XPath表达式不能更改文档(通过创建或删除节点)。你需要做的是将文档转换成另一个XML文档。 XSLT是一种特别为XML转换而设计的语言,而这种特定的转换对于XSLT来说是微不足道的。你会对获得XSLT解决方案感兴趣吗? –

回答

0

我认为(但我不能肯定)要$nodelist包含所有td元件,其class属性开始字符串value但如果它们包含img元素

如果这是你的问题的正确解释,更改

$nodelist = $xpath->query("//tr/td[substring(@class,1,5)='value']"); 

$nodelist = $xpath->query("//tr/td[substring(@class,1,5)='value'][not(img)]"); 

我不知道你要在你的第二个示例表办的温度值它是什么;您可能想要编辑问题以明确您是否要检索它们。