Reputation: 699
I am trying to write an XPath expression that selects all the nodes only where the title of the movie matches the name of the actor. For example the following should return only B
<main>
<movies>
<movie title="A">
</movie>
<movie title="B">
</movie>
<movie title="C">
</movie>
</movies>
<actors>
<actor title="Z" name="someone">
</actor>
<actor title="D" name="somebody">
</actor>
<actor title="B" name="awesome name">
</actor>
</actors>
</main>
I have played around with different paths but I can't seem to get it to work. It seems like this should but I am not having any luck. Any suggestions are appreciated. Thanks
main/movies/movie/[@title = main/actors/actor/@title]
Upvotes: 0
Views: 79
Reputation: 241738
In predicates (i.e. square brackets), any relative path starts at the node reached so far. There's no main
under movie
, you want the root node again, so you have to prepend the /
:
/main/movies/movie[@title = /main/actors/actor/@title]
^
Upvotes: 1