2

たとえば、xpath を使用して、テキストのstrong後にタグを選択するにはどうすればよいでしょうか。baz

<p>
<br>foo<strong>this foo</strong>

<br>bar<strong>this bar</strong>

<br>baz<strong>this baz</strong>

<br>qux<strong>this qux</strong></p>

明らかに、以下は機能しません....

//p[text() = 'baz']/following-sibling::select[1]
4

1 に答える 1

3

これを試して

//p/text()[. = 'baz']/following-sibling::strong[1]

デモはこちら - http://www.xpathtester.com/obj/b67bad4d-4d38-4e2d-a3df-b7e5a2e9f286

このソリューションは、テキスト ノードの周囲に空白がないことに依存しています。インデントやその他の空白文字の使用を開始する場合は、次の使用に切り替える必要があります。

//p/text()[normalize-space(.) = 'baz']/following-sibling::strong[1]
于 2013-02-28T04:12:34.783 に答える