想在Xquery的“where”子句中包含“for”语句

时间:2014-11-17 07:31:03

标签: xml 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行。 这是错误的语法吗?如何写一个" for"循环在"其中"条款?

1 个答案:

答案 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)