xpath preceding-sibling select

xpath preceding-sibling select

有人可以给我提示如何根据 svg class="svg svg-goal" 获得 "Some text1" 吗?

这个有效

$x("//br/../preceding-sibling::strong/a")

这不行

$x("//svg[@class='svg svg-goal']/../preceding-sibling::span/strong/a")

层级 HTML 代码

<span class="event-p-name">
    <strong>
        <a href="">Some text1</a>
    </strong>
    <small>
        <br>Some text2</br>
    </small>
</span>
<span class="event-type">
    <svg class="svg svg-goal">
        <use xlink:href="/public/themes/svg/symbol-defs.svg#football"></use>
    </svg>
</span>

谢谢

试试这个

//svg[@class='svg svg-goal']/preceding::span/strong/a

结果

<a href="">Some text1</a>

对于 <svg> 元素(及其子元素),您需要使用 //*[name()='svg'] 语法。尝试以下:

//*[name()='svg' and @class='svg svg-goal']/../preceding-sibling::span/strong/