KJW
KJW

Reputation: 15251

xpath: decipher this xpath?

what does this xpath mean ? can someone decipher this ?

//h1[following-sibling::*[1][self::b]]

Upvotes: 6

Views: 764

Answers (1)

LarsH
LarsH

Reputation: 27996

Select every h1 element (in the document of the context node) that is immediately followed by a b element (with no other intervening element, though there may be intervening text).

Breaking it down:

//h1

Select every h1 element that is a descendant of the root node of the document that contains the context node;

[...]

filter out any of these h1 elements that don't meet the following criteria:

[following-sibling::*[1]...]

such that the first following sibling element passes this test:

[self::b]

self is a b element. Literally, this last test means, "such that when I start from the context node and select the self (i.e. the context node) subject to the node test that filters out everything except elements named b, the result is a non-empty node set."

Upvotes: 23

Related Questions