2014-11-17 61 views
0

我試圖運行下面的XQuery:想擁有一個「爲」語句「其中」子句中XQuery中

for $a1 in doc("TSS_Data.xml")/root/auditions/audition, $a2 in doc("TSS_Data.xml")/root/auditions/audition 
where ($a1/@ID != $a2/@ID and $a1/@contestantId != $a2/@contestantId and $a1/@artworkId = $a2/@artworkId and 
$a1/@showId = $a2/@showId) 
    for $s1 in doc("TSS_Data.xml")/root/scores/score[@auditionId = $a1/@ID], 
    $s2 in doc("TSS_Data.xml")/root/scores/score[@auditionId = $a2/@ID] 
     return data (doc("TSS_Data.xml")/root/contestants/contestant[@ID = $a1/@contestantId]/@name) 

但我得到一個錯誤,意外標記「爲」 4行。 這是錯誤的語法嗎?我如何在「where」子句中編寫「for」循環?

回答

1

A for總是需要return語句,就像在內部循環中一樣。因此,它應該是

for $a1 in doc("TSS_Data.xml")/root/auditions/audition, $a2 in doc("TSS_Data.xml")/root/auditions/audition 
where ($a1/@ID != $a2/@ID and $a1/@contestantId != $a2/@contestantId and $a1/@artworkId = $a2/@artworkId and $a1/@showId = $a2/@showId) 
return 
    for $s1 in doc("TSS_Data.xml")/root/scores/score[@auditionId = $a1/@ID], 
    $s2 in doc("TSS_Data.xml")/root/scores/score[@auditionId = $a2/@ID] 
     return data (doc("TSS_Data.xml")/root/contestants/contestant[@ID = $a1/@contestantId]/@name)