Xml 按公共条件属性列出属性

Xml 按公共条件属性列出属性,xml,loops,xquery,Xml,Loops,Xquery,我有一个关于Xquery的问题。 我的目标是将循环中具有相同属性但与另一个属性不同的所有元素显示到不同的元素中。已经48小时了,我被困在这上面了,我不能前进了( 下面是我得到的表格类型示例: <people> <crazy id="123" firstname="John" lastname="Fool" score="20"> <crazy id="123" firstname="John" lastname="Fool" score="80"> <c

我有一个关于Xquery的问题。 我的目标是将循环中具有相同属性但与另一个属性不同的所有元素显示到不同的元素中。已经48小时了,我被困在这上面了,我不能前进了(

下面是我得到的表格类型示例:

<people>
<crazy id="123" firstname="John" lastname="Fool" score="20">
<crazy id="123" firstname="John" lastname="Fool" score="80">
<crazy id="123" firstname="John" lastname="Fool" score="77">
<crazy id="123" firstname="John" lastname="Fool" score="49">
<crazy id="789" firstname="Lea" lastname="Dumb" score="54">
<crazy id="789" firstname="Lea" lastname="Dumb" score="89">
<crazy id="789" firstname="Lea" lastname="Dumb" score="99">
<crazy id="789" firstname="Lea" lastname="Dumb" score="4">
<crazy id="247" firstname="Paul" lastname="Duck" score="16">
<crazy id="247" firstname="Paul" lastname="Duck" score="91">
<crazy id="247" firstname="Paul" lastname="Duck" score="22">
<crazy id="247" firstname="Paul" lastname="Duck" score="31">
</people>
现在我想列出少于2个“得分”大于50的人数。
但是我不知道如何继续:(:(

我不是100%确定你想要什么,但我认为是这样的:

for $id in distinct-values(//crazy/@id)
  where count(//crazy[@id = $id and number(@score) gt  50]) lt 2
return <person>{$id}</person>
不同值(//crazy/@id)中的$id的

其中count(//疯狂[@id=$id和number(@score)gt 50])lt 2
返回{$id}
 let $calc:= (

  for $boucle in people where ($boucle/@score>="50")
  return $boucle

)
for $id in distinct-values(//crazy/@id)
  where count(//crazy[@id = $id and number(@score) gt  50]) lt 2
return <person>{$id}</person>