gpt4 book ai didi

XPath "following siblings before"

转载 作者:行者123 更新时间:2023-12-03 15:46:51 24 4
gpt4 key购买 nike

<img><b>First</b><br>&nbsp;&nbsp;
<img>&nbsp;&nbsp;<a href="/first-href">First Href</a> - 19:30<br>
<img><b>Second</b><br>&nbsp;&nbsp;
<img>&nbsp;&nbsp;<a href="/second-href">Second Href</a> - 19:30<br>
<img>&nbsp;&nbsp;<a href="/third-href">Third Href</a> - 19:30<br>

我试图让样本尽可能接近真实世界。所以在这种情况下,当我在 element

<b>First</b>

我需要选择

<a href="/first-href">First Href</a> 

当我在

<b>Second</b> 

我需要选择

<a href="/second-href">Second Href</a> 
<a href="/third-href">Third Href</a>

知道如何实现吗?谢谢!

最佳答案

动态创建此 XPath:

following-sibling::a[preceding-sibling::b[1][.='xxxx']]

其中 'xxxx' 被替换为当前 <b> 的文本.

这是假设所有元素实际上都是 sibling 。如果不是,您可以尝试使用 precedingfollowing axes,或者您编写更类似于文档结构的更具体的 XPath。

在 XSLT 中,您还可以使用:

following-sibling::a[
generate-id(preceding-sibling::b[1]) = generate-id(current())
]

关于XPath "following siblings before",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2280670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com