0

With the next xml, how coud i get the list of directors where two directors has the same LastName in one movie?

<MoviesLib>
  <Movie Title="Batman" Year="2013">
    <Directors>
      <Director>
        <Name>Robert</Name>
        <LastName>Zemeckis</LastName>
      </Director>
    </Directors>
  </Movie>
  <Movie Title="Gru" Year="2012">
    <Directors>
      <Director>
        <Name>john</Name>
        <LastName>tailer</LastName>
      </Director>
      <Director>
        <Name>Emma</Name>
        <LastName>Smith</LastName>
      </Director>
      <Director>
        <Name>Lana</Name>
        <LastName>Smith</LastName>
      </Director>
    </Directors>
  </Movie>
</MoviesLib>

for example in this case would be: Emma Smith, Lana Smith

thanks

1 Answers1

0

The following XPath 2.0 expression should work:

for $d in //Director
    return $d[../Director[not(. is $d) and LastName = $d/LastName]]

I can't come up with a single XPath 1.0 expression since it doesn't support for expressions (see the question How to get the context of outer predicate? for some background).

Community
  • 1
  • 1
nwellnhof
  • 32,319
  • 7
  • 89
  • 113