【问题标题】:Is there anything similar to an if-else in XPath?XPath 中有没有类似于 if-else 的东西?
【发布时间】:2016-06-17 16:37:18
【问题描述】:

我想检查 HTML 中的某个文本,例如“无值”,如果存在,则为其分配 0。有人知道该怎么做吗? (谷歌了很多,但没有找到任何相关的东西)

<table>
<tr>
<td>
<h3>Money in account</h3>
</td>
<td>
<p>No Value</p>
</td>
</tr>
</table>

【问题讨论】:

标签: html xpath domxpath xpathquery


【解决方案1】:

在 XPath 2.0 中:

if (p = 'No Value') then 0 else p

在 XPath 1.0 中没有明显的解决方案,但有一些复杂的解决方法:这在一定程度上取决于您工作的上下文(例如,您可以声明变量)。

是时候迁移到 XPath 2.0了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-16
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多