0
declare variable $testseq as item()* :=();
declare function local:insertseq($target as item()*, $position as xs:integer?, $inserts as item()*)
as item()* (:might be great if we have a keyword to represent nothing:)
{
fn:insert-before($target, 1, $inserts) (:change the global sequence:)
() (:simulate returning nothing, empty sequence:)
};
element test
{
attribute haha {"&"},
local:insertseq($testseq, 1, ('a', 'b')),
$testseq
}
我需要在脚本运行时将某些东西收集到全局序列中。在脚本结尾我释放序列。函数insertseq
必须不返回任何内容。 XQuery有可能吗?或者还有其他的技巧可以做到吗?从BaseXXQuery:声明函数不返回
错误:
$ basex test.xqy
Stopped at /Users/jack/Documents/SHK/XSD2OWL/Workspace/xqy/test.xqy, 7/4:
[XPTY0004] Item expected, sequence found: ("a", "b").
XQuery是一种功能性语言。即使你使用'insert-before'也是不正确的:它不会修改任何内容,它会返回一个新的序列。你需要重新思考你在输入/输出方面做了什么;如果在处理结束时需要一个序列,那么该序列将需要成为返回值的一部分。 –
某些实现有一个“脚本”扩展,其中有可变变量 – BeniBela