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