XML: Return 个满足给定条件的序列元素
XML: Return elements of a sequence that satisfy given condition
我有一个包含电影信息的 XML 文件。我想表达我对 return XML 导演超过 1 部电影的导演的表达。
我现在拥有的是:
for $director in //director
where count($director) > 1
return $director
这不会产生任何结果。我想做的是:
对于 XML 中的每一位董事:
return导演的名字如果导演的名字在//director
中被多次提及
你会如何解决这个问题?
编辑: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>
您根本没有执行聚合。如果您的 XQuery 引擎支持 XQuery 3.0,请使用 group by
:
for $director in //director
where count($director) > 1
group by $director
return $director
否则,遍历所有 distinct-values(//director)
,找到每个名称的所有匹配导演标签并计算它们。
我有一个包含电影信息的 XML 文件。我想表达我对 return XML 导演超过 1 部电影的导演的表达。
我现在拥有的是:
for $director in //director
where count($director) > 1
return $director
这不会产生任何结果。我想做的是:
对于 XML 中的每一位董事: return导演的名字如果导演的名字在//director
中被多次提及你会如何解决这个问题?
编辑: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>
您根本没有执行聚合。如果您的 XQuery 引擎支持 XQuery 3.0,请使用 group by
:
for $director in //director
where count($director) > 1
group by $director
return $director
否则,遍历所有 distinct-values(//director)
,找到每个名称的所有匹配导演标签并计算它们。