我正在尝试运行以下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行。 这是错误的语法吗?如何写一个" for"循环在"其中"条款?
答案 0 :(得分:1)
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)