Re: XPath question: selecting content between two nodes
In article <1141765206.022734.63800@j52g2000cwj.googlegroups. com>,
Yoav Shapira <yoavshapira@gmail.com> wrote:
[color=blue]
><img src="uniqueUrl1" />
><p>some text</p>
><p>some other text</p>
><p>some more text</p>
><img src="uniqueUrl2" />[/color]
[color=blue]
>Now, my question: given unique URLs 1 and 2, how do I select all the
>content between the two img nodes?[/color]
[color=blue]
>I thought //img[@src="uniqueUrl1"] would work for the first image and
>//img[@src="uniqueUrl2"] for the second image node, but they don't seen
>to[/color]
Well, I can't solve that problem, because those XPaths *do* select
the nodes in question! If it's not working for you, you are using them
wrongly.
[color=blue]
> and anyways they don't give me the content between. I know of the
>following axis, but not sure how to use it if it's applicable here at
>all.[/color]
Something like this will select the nodes between the two <img>
elements. It uses the following-sibling axis to get the sibling nodes
after the first <img>, and restricts them to the ones that have the
second <img> as a following-sibling.
//img[@src="uniqueUrl1"]/following-sibling::node()[following-sibling::img[@src="uniqueUrl2"]]
-- Richard
|