When I try to execute my Xquery Code on xml file, I am getting multiple results in one of my fields.
Here is my xml file
<Actors>
<Actor name="NTR">
<Movie TITLE="Yamadonga" Director="Rajamouli"></Movie>
<Movie TITLE="AADI" Director="VV vinayak">
</Movie>
</Actor>
<Actor name="Rajeev">
<Movie TITLE="Yamadonga" Director="Rajamouli" ></Movie>
</Actor>
<Actor name="mahesh">
<Movie TITLE="pokiri" Director="puri">
</Movie>
</Actor>
my xquery file
<Director>
{
for $Movie in doc("actors.xml")/Actors/Actor/Movie
return
if($Movie/@TITLE=$title)
then
data($Movie/@Director)
else()
}
</Director>
Most importantly, my result
<movies>
<movie>
<Title>Yamadonga</Title>
<Actor>NTR</Actor>
<Actor>Rajeev</Actor>
<Director>Rajamouli Rajamouli</Director>
</movie>
</movies>
How to get only one value in the director field?
My procedure :- I ran the distinct values function over (../Movie/@TITLE) and that gave me the answer for displaying title. But as title and director are attributes of movie, I cannot access one using the other. When I iterate over actor, as there are two actors having a single director for single movie, the director name gets printed twice. When I iterate over movie, I cannot use distinct-values over it as it is not an attribute.