【发布时间】:2014-06-09 12:42:14
【问题描述】:
我有以下 xml 文件。我需要找到不在 $v 中的 $c 中的成员:
(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>
我试过了,这也行不通:
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 except $v将始终为空。这与您的原始查询不同吗? -
@LeoWörteler 我已经编辑并添加了我的 XML 文件。
标签: xml xquery xquery-sql