How to get a node that is in front of another?

I have this XML:

<movies>
<movie>
    <title>A History of Violence</title>
</movie>
<movie>
    <title>Heat</title>     
</movie>
</movies>

And I want to get the first film, but said that bring me the film that was before Heat.

+4
source share
1 answer

Good use case preceding:

//movie/title[. = "Heat"]/preceding::movie

Or preceding-sibling:

//movie[title = "Heat"]/preceding-sibling::movie
+6
source

Source: https://habr.com/ru/post/1623333/


All Articles