XQuery如何用 "where "条件来计算。

问题描述 投票:0回答:1

我刚刚开始学习XQuery,我希望它能显示我的音乐节的数量与genre(genero)是相同的 "金属"。我不能得到他们的总数,只能分别。

XQuery

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>

谢谢!我刚开始学习XQuery,我想让它显示我的节日数量与genre(genero)是相同的 "金属"。

count where-clause xquery-3.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>
© www.soinside.com 2019 - 2024. All rights reserved.