0

我刚刚开始学习 XQuery,我希望它向我展示流派 (genero) 的音乐节数量与“金属”相同。我不能得到它们的总数,只能分开。

查询

for $b in //festival
where $b/@genero="Metal"
return <prueba>{count ($b/@genero="Metal"), $b//nombre}</prueba>

XML

  <Festivales>
    <festival genero="Metal">
        <informacion>
            <nombre>Resurrection Fest</nombre>
            <fecha_inicio>2020-07-01</fecha_inicio>
            <fecha_fin>2020-07-04</fecha_fin>
    </festival>
    <festival genero="Rock-Heavy Metal">
        <informacion>
            <nombre>Rock the Night</nombre>
            <fecha_inicio>2020-06-26</fecha_inicio>
            <fecha_fin>2020-06-27</fecha_fin>
    </festival>
    <festival genero="Hardcore">
        <informacion>
            <nombre>Ieperfest</nombre>
            <fecha_inicio>2020-07-03</fecha_inicio>
            <fecha_fin>2020-07-05</fecha_fin>
        </informacion>
    </festival>
    <festival genero="Metal">
        <informacion>
            <nombre>Download UK</nombre>
            <fecha_inicio>2020-06-12</fecha_inicio>
            <fecha_fin>2020-06-14</fecha_fin>
        </informacion>
    </festival>
</Festivales>

结果

<prueba>1<nombre>Resurrection Fest</nombre>
</prueba>
<prueba>1<nombre>Hellfest</nombre>
</prueba>
<prueba>1<nombre>Download UK</nombre>
</prueba>

谢谢!

4

1 回答 1

0
for $b in //festival[@genero="Metal"]
let $n := $b/informacion/nombre/text()
return 
    <prueba>
        {
            <cnt>{count(//festival[@genero="Metal"]/informacion/nombre[. = $n])}</cnt>
          , $b/informacion/nombre
        }
   </prueba>
于 2020-05-02T11:55:56.297 回答