我对 xQuery 很陌生,我必须编写以下查询;
显示每个导演的 DVD 标题。
我的 xQuery 是;
let $doc := doc("DVDStore.xml")//DVDTitle
return <Directors>{
for $dir in $doc/Directors/Name
let $t := $doc[$dir = Directors/Name]/Title
return <DVDTitles> {$dir} {$t} </DVDTitles>
} </Directors>
DVDStore.xml 是;
<?xml version="1.0" encoding="UTF-8"?>
<DVDStore>
<DVDTitles>
<DVDTitle>
<Title>A. I. Artificial Intelligence</Title>
<Date>2002-03-05</Date>
<Studio>Universal Studios</Studio>
<Rated>PG-13</Rated>
<Code>1</Code>
<Directors>
<Name>Steven Spielberg</Name>
</Directors>
<Starrings>
<Name>Haley Joel Osment</Name>
<Name>Jude Law</Name>
</Starrings>
</DVDTitle>
<DVDTitle>
<Title>Terminator 2-Judgment Day</Title>
<Date>2001-01-01</Date>
<Studio>Artisan Entertainment</Studio>
<Rated>R</Rated>
<Code>6</Code>
<Directors>
<Name>James Cameron</Name>
</Directors>
<Starrings>
<Name>Arnold Schwarzenegger</Name>
<Name>Linda Hamilton</Name>
</Starrings>
</DVDTitle>
<DVDTitle>
<Title>Titanic</Title>
<Date>1999-08-31</Date>
<Studio>Paramount Home Video</Studio>
<Rated>PG-13</Rated>
<Code>2</Code>
<Directors>
<Name>James Cameron</Name>
</Directors>
<Starrings>
<Name>Leonardo DiCaprio</Name>
<Name>Kate Winslet</Name>
</Starrings>
</DVDTitle>
</DVDTitles>
</DVDStore>
我得到以下输出;
<?xml version="1.0" encoding="UTF-8"?>
<Directors>
<DVDTitles>
<Name>Steven Spielberg</Name>
<Title>A. I. Artificial Intelligence</Title>
</DVDTitles>
<DVDTitles>
<Name>James Cameron</Name>
<Title>Terminator 2-Judgment Day</Title>
<Title>Titanic</Title>
</DVDTitles>
<DVDTitles>
<Name>James Cameron</Name>
<Title>Terminator 2-Judgment Day</Title>
<Title>Titanic</Title>
</DVDTitles>
</Directors>
问题是,当一位导演导演了两部电影或多部电影时,就像James Cameron
导演了一样Terminator 2-Judgment Day
,Titanic
然后这两个标题都应该与发生正确的导演分组,但我得到了两次(见输出)。
有人可以帮忙吗?