在阅读了有关检测空节点的最相关的Xpath问题之后,我仍然找不到第一个非空元素。该数据集的样子:检测第一个非空元素
<div>
<p>
<elem> </elem>
</p>
<p>
<elem> </elem>
</p>
<p>
<elem> </elem>
</p>
<p>
<elem>   </elem>
</p>
<p>
<elem>Application</elem>
</p>
<p>
<elem>Other text that should not be detected.</elem>
</p>
<p>
<elem> </elem>
</p>
<p>
<elem>Second application</elem>
</p>
</div>
基本上空元素不应该被考虑进去,而我们只需要检测第一Application
元素。我们已经用normalize-space
以及相关功能进行了很多测试,但无法正常工作。
主要问题是空的元素。我们现在所拥有的支票解决了定位完美,但一旦HTML包含
元素失败:
/div/p[position() < 3]//*[normalize-space()='Application']
那么,我们怎么能忽略空元素?这只能通过一个额外的步骤之间?
问题是,你没有*空*元素在首位。 'normalize-space()'只规范化空白字符 - 我不确定它是否规范化了' '元素(我假设是这样,因为它们基本上是换行符),但它肯定不会触及' '因为没有中断空格是特殊字符而不是用于该功能的普通空格。 – BoltClock