XML:返回出现特定次数的序列元素 [英] XML: Return elements of a sequence that occur certain number of times
本文介绍了XML:返回出现特定次数的序列元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含电影信息的 XML 文件.我希望我的表达式返回 XML 中导演超过 1 部电影的导演.
I have an XML file with information on movies. I want my expression to return the directors in the XML that have directed more than 1 movie.
我现在拥有的是:
for $director in //director
where count($director) > 1
return $director
This does not produce anything.
我想做的是:
For every director in the XML:
return director's name IF the director's name occurs more than once in //director
你会如何解决这个问题?
How would you solve this problem?
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>
推荐答案
试试这个:
for $director in distinct-values(//director)
where count(//video[director = $director]) > 1
return $director
这篇关于XML:返回出现特定次数的序列元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文