【发布时间】:2014-09-22 20:47:24
【问题描述】:
我试图从 XML 文档(它实际上是一个转换为 XML 的 HTML 表)中找到某个元素的最小值。但是,这并没有按预期工作。
该查询类似于How can I use XPath to find the minimum value of an attribute in a set of elements? 中使用的查询。它看起来像这样:
/table[@id="search-result-0"]/tbody/tr[
not(substring-before(td[1], " ") > substring-before(../tr/td[1], " "))
]
在示例 XML 上执行
<table class="tablesorter" id="search-result-0">
<thead>
<tr>
<th class="header headerSortDown">Preis</th>
<th class="header headerSortDown">Zustand</th>
</tr>
</thead>
<tbody>
<tr>
<td width="45px">15 CHF</td>
<td width="175px">Ausgepack und doch nie gebraucht</td>
</tr>
<tr>
<td width="45px">20 CHF</td>
<td width="175px">Ausgepack und doch nie gebraucht</td>
</tr>
<tr>
<td width="45px">25 CHF</td>
<td width="175px">Ausgepack und doch nie gebraucht</td>
</tr>
<tr>
<td width="45px">35 CHF</td>
<td width="175px">Ausgepack und doch nie gebraucht</td>
</tr>
<tr>
<td width="45px">14 CHF</td>
<td width="175px">Gebraucht, aber noch in Ordnung</td>
</tr>
<tr>
<td width="45px">15 CHF</td>
<td width="175px">Gebraucht, aber noch in Ordnung</td>
</tr>
<tr>
<td width="45px">15 CHF</td>
<td width="175px">Gebraucht, aber noch in Ordnung</td>
</tr>
</tbody>
</table>
查询返回以下结果:
<tr>
<td width="45px">15 CHF</td>
<td width="175px">Ausgepack und doch nie gebraucht</td>
</tr>
-----------------------
<tr>
<td width="45px">14 CHF</td>
<td width="175px">Gebraucht, aber noch in Ordnung</td>
</tr>
-----------------------
<tr>
<td width="45px">15 CHF</td>
<td width="175px">Gebraucht, aber noch in Ordnung</td>
</tr>
-----------------------
<tr>
<td width="45px">15 CHF</td>
<td width="175px">Gebraucht, aber noch in Ordnung</td>
</tr>
为什么返回的节点多于一个?因为只有一个最小值,所以应该只返回一个节点。有人看到查询有什么问题吗?它应该只返回包含14 CHF 的节点。
【问题讨论】: