我注意到 XQuery 实现如何处理(子)类型的细微差别。特别是,将文字数字处理为声明了接受的输入类型的函数的输入。我天真地认为任何可转换为该特定数字类型的数字文字都会被接受。
declare function local:any ($n as xs:anyAtomic) { $n };
declare function local:decimal ($n as xs:decimal) { $n };
declare function local:integer ($n as xs:integer) { $n };
declare function local:pos-int ($n as xs:positiveInteger) { $n };
local:any(1), (: works :)
local:decimal(1), (: works :)
local:integer(1), (: works :)
local:pos-int(1) (: throws in all tested implementations :)
exists-db 允许xs:long
, xs:int
, ... Saxon 不允许。
我在 Xquery Spec 2.5.5 SequenceType Matching 和 Xpath functions spec 1.6.3 Atomic Type Hierarchy中找不到该行为的任何原因
有人可以解释一下为什么 Saxon 9.3.1 HE、BaseX 9.3.1 [Standalone] 和 eXist 5.3.0-SNAPSHOT 会这样吗?
我是否错过了规范中定义将文字1
转换为 xs:integer 的部分?xs:decimal 作为最顶层的类型会更有意义,但是如果允许一个子类型,为什么不一直走呢?