XPATH 选择包含具有特定 href 的锚点的范围

问题描述 投票:0回答:1

我正在尝试编写一个 XPath 语句,该语句选择具有给定类的

span
,该类包含具有给定
href
的锚点。这就是我现在拥有的:

//span[.[contains(@class, 'versiontext')]/a[contains(@href, 'esv')]]

当我在

http://xpather.com/
测试它时,它按预期工作,但是当我使用
xsltproc
在本地运行它时,会生成此错误:

XPath error : Invalid predicate
//span[.[contains(@class, 'versiontext')]/a[contains(@href, 'esv')]]
        ^

我的 XPath 中是否存在错误,或者这只是

xsltproc
的限制?

这是我将模板应用到的 .html 的一部分:

 <span class="versiontext"><a href="/nlt/leviticus/1.htm">New Living Translation</a></span><br />The LORD called to Moses from the Tabernacle and said to him,<span class="p"><br /><br /></span>
                        
<span class="versiontext"><a href="/esv/leviticus/1.htm">English Standard Version</a></span><br />The LORD called Moses and spoke to him from the tent of meeting, saying,<span class="p"><br /><br /></span>
                        
<span class="versiontext"><a href="/bsb/leviticus/1.htm">Berean Standard Bible</a></span><br />Then the LORD called to Moses and spoke to him from the Tent of Meeting, saying,<span class="p"><br /><br /></span>

<span class="versiontext"><a href="/kjv/leviticus/1.htm">King James Bible</a></span><br />And the LORD called unto Moses, and spake unto him out of the tabernacle of the congregation, saying,<span class="p"><br /><br /></span>
xpath xslt
1个回答
0
投票

这只是

xsltproc
的限制吗?

我在其他 XSLT 1.0 处理器上遇到了同样的错误(但在支持 XSLT 3.0 的 Saxon 10 上却没有)。我不确定对此有一个很好的解释,但可以通过使用来消除它:

//span[contains(@class, 'versiontext')]/a[contains(@href, 'esv')]

相反。

© www.soinside.com 2019 - 2024. All rights reserved.