【发布时间】:2015-09-08 10:22:57
【问题描述】:
我遇到了以下问题,语法方面我不确定为什么会得到我得到的结果。
我有以下 FLOWR 表达式:
(: example 1 :)
for $attr in $node/@*
where $attr/fn:local-name != ("src", "type", "id")
return $attr
这个在我心里的英文版是:Get me all the attributes that are not src, type, or id。
但是,当我运行它时,会返回每个属性,包括 src, type, and id。当我将where 语句更改为只有一个元素where $attr/fn:local-name != ("src") 时,这将按预期工作- 除了src 之外的所有属性都会返回。奇怪的是,它在与一个元素进行比较时有效,而不是与三个元素进行比较。
如果我颠倒我的逻辑,做出这样的陈述:
(: example 2 :)
for $attr in $node/@*
where $attr/fn:local-name = ("src", "type", "id")
return $attr
(: difference is = instead of != :)
然后我也得到了我期望的结果,这只是 "src", "type", and "id" 的 3 个属性,仅此而已。
所以,回到我原来的案例,为了让它按我期望的方式工作,我必须使用以下语句:
(: example 3 :)
for $attr in $node/@*
where fn:not($attr/fn:local-name = ("src", "type", "id"))
return $attr
这将返回除src, type, and id 之外的所有属性。
为什么会发生这种情况?在我看来,example 1 和 example 3 应该做同样的事情。但是,我无法让 example 1 以我期望的方式工作。
我的问题的 xPath 等效项类似于:
$node/@*[fn:not(./fn:local-name(.) = ("src", "type", "id"))]
谁能解释我的想法哪里有问题?
我正在使用xquery version "1.0-ml"。
【问题讨论】: