XPath 中是否有类似 if-else 的东西?

Is there anything similar to an if-else in XPath?

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

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

在 XPath 2.0 中:

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

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

是时候迁移到 XPath 2.0 了。