2015-10-03 49 views
-1

我有一個包含電影信息的XML文件。我希望我的表達能夠返回指向多個電影的XML中的導演。XML:返回滿足給定條件的序列元素

我現在擁有的是:

for $director in //director 
where count($director) > 1 
return $director 

這不會產生任何東西。我正在試圖做的是:

對於在XML每名董事: 回報導演的名字,如果導演的名字被命名爲比//主任

你將如何解決這個問題再一次?

編輯:XML的示例:

<result> 
    <videos> 
     <video id="id1235AA0"> 
      <title>The Fugitive</title> 
      <genre>action</genre> 
      <rating>PG-13</rating> 
      <summary>Tommy Lee Jones and Harrison Ford are the hunter and the hunted in this fast-paced story of a falsely convicted man who escapes to find his wife's true killer.</summary> 
      <details>Harrison Ford and Tommy Lee Jones race through the breathless manhunt movie based on the classic TV series. Ford is prison escapee Dr. Richard Kimble, a Chicago surgeon falsely convicted of killing his wife and determined to prove his innocence by leading his pursuers to the one-armed man who actually commited the crime.</details> 
      <year>1997</year> 
      <director>Andrew Davis</director> 
      <studio>Warner</studio> 
      <user_rating>4</user_rating> 
      <runtime>110</runtime> 
      <actorRef>00000003</actorRef> 
      <actorRef>00000006</actorRef> 
      <vhs>13.99</vhs> 
      <vhs_stock>206</vhs_stock> 
      <dvd>14.99</dvd> 
      <dvd_stock>125</dvd_stock> 
      <beta>1.03</beta> 
      <beta_stock>12</beta_stock> 
      <LaserDisk>12.00</LaserDisk> 
      <LaserDisk_stock>10</LaserDisk_stock> 
     </video> 
    </videos> 
</result> 
+0

如果您想列出擁有多部電影的導演,請務必提供一個實際適用於您的問題的示例:我會建議至少有三部電影,兩部使用相同的導演,另一部使用另一部,所以有兩個導演匹配,而那些導演不匹配。與此同時,您可以省略大部分其他不相關的標籤。 –

+0

而且不要發佈[完全相同的問題多次](http://stackoverflow.com/questions/32924082/xml-return-elements-of-a-sequence-that-occur-certain-number-of-times )。 –

回答

1

你不能在所有執行聚集。如果您的XQuery引擎支持的XQuery 3.0,使用group by

for $director in //director 
where count($director) > 1 
group by $director 
return $director 

否則,遍歷所有distinct-values(//director),找到每個名字的所有匹配主任標籤和計數。