如何使用xquery返回某個索引處的值?例如,如果這是我的xml文件:使用xquery獲取索引值?
<game>
<team>
<player>id="1"</player>
<player>id="2"</player>
</team>
<team>
<player>id="3"</player>
<player>id="4"</player>
</team>
<team>
<player>id="5"</player>
<player>id="6"</player>
</team>
</game>
說我要回各隊的第一個玩家ID,這樣我就得到1,3,5,如何將我寫這篇文章的查詢?我試過這樣的東西,但它不起作用:
for $team in doc("game.xml")//team
return data($team/player/@id[1])
任何幫助,將不勝感激。謝謝。
嘗試應'id's會有玩家標籤作爲屬性的一部分? –