我是 xquery 的新手,我正在嘗試計算每個音樂家擁有的專輯數量。
我的資料如下:
<musicians>
<musician type="band">
<name>If These Trees Could Talk</name>
<genre>Post-Rock</genre>
<albums>
<album year="2006">If These Trees Could Talk</album>
<album year="2009">Above the Earth, Below the Sky</album>
</albums>
</musician>
<musician type="solo">
<name>Justin Bergh</name>
<genre>Pop-Rock</genre>
<albums>
<album year="2005">Out of My Hands</album>
<album year="2010">Lateralus</album>
</albums>
</musician>
<musician type="band">
<name>Tool</name>
<genre>Progressive Metal</genre>
<albums>
<album year="1993">Undertow</album>
<album year="1996">Aenima</album>
<album year="2001">Lateralus</album>
<album year="2006">10,000 Days</album>
</albums>
</musician>
</musicians>
預期輸出:
2
2
4
我目前的代碼:
for $n in //musicians/musician/albums
let $count := count($n)
return $count
我的輸出是
1
1
1
uj5u.com熱心網友回復:
您目前正在計算albums元素的數量,而您的目標是計算album元素。
更改您的代碼如下:
for $n in //musicians/musician/albums
let $count := count($n/album)
return $count
這將產生所需的輸出:
2
2
4
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339835.html
上一篇:我需要回傳JSON作為美容表樣式
