我有以下的XML文件。我需要找到成員是在$ C這是不是在$ V:爲什麼簡單的兩組減法不起作用?
(C) - (V) = desired result
let $c := /transport/trips/trip
let $v := /transport/trips/trip
where (data($c/@vehicle)="PKR856")
return
<result2>
{$v/(from|to|through)/string()}
{$c/(from|to|through)/string()}
</result2>
現在我婉減去他們,這裏是我的代碼:
let $c := /transport/trips/trip
let $v := /transport/trips/trip
where (data($c/@vehicle)="PKR856")
return
<result2>
{ $c/(from|to|through)/string()[not(. = $v/(from|to|through)/string())]}
</result2>
我已經試過這還不算workoing :
let $c := /transport/trips/trip/
let $v := /transport/trips/trip/(from|to|through)/string()
where (data($c/@vehicle)="PKR856")
return
<result2>
{ $c/(from|to|through)/string()[not(. = $v)]}
</result2>
輸出:
內部錯誤代碼,參數
編輯
下面是XML文件:
<trips>
<trip driver="d2345" vehicle="PKR856" date="12-DEC-2007">
<from>London</from>
<to>Newcastle</to>
<through stop="1">Leicester</through>
<through stop="2">Nottingham</through>
<time>1</time>
</trip>
<trip driver="d6767" vehicle="UUQ007" date="10-MAY-2008">
<from>Paris</from>
<to>Rome</to>
<through stop="1">Lyon</through>
<through stop="2">Milan</through>
<time>15</time>
</trip>
<trip driver="d2345" vehicle="PKR856" date="14-DEC-2007">
<from>Paris</from>
<to>Amsterdam</to>
<through stop="2">Brussel</through>
<through stop="1">Mons</through>
<time>4</time>
</trip>
</trips>
我需要回到城市的名字並沒有被具體車號訪問?
我嘗試了這些,但不工作:
let $driver-cities := /trips/trip[@vehicle="PKR856"]/(from, to, through)/string()
return /trips/trip/(from, to)/string()[not(. = $driver-cities)]
其實我的答案更改爲:
let $c := /transport/trips/trip/(from|to|through)/text()
let $v := /transport/trips/trip[@vehicle eq "PKR856"]/(from|to|through)/text()
return
<result>
{ $c except $v}
</result>
你能提供一個例子文件? '$ c'和'$ v'是相同的,所以'$ c除了$ v'將一直是空的。你的原始查詢有什麼不同? –
@LeoWörteler我編輯並添加了我的XML文件。 – Bernard