使用MarkLogic Xquery,我有一個函數(admin:add-collection-to-publication)
,它調用另一個維護函數(admin:check-collections-exists)
,它檢查元素的存在,如果它不存在,則創建該特定元素。xquery在另一個函數中調用維護功能
我稱之爲維護功能的方式是使用讓。這看起來像一個奇怪的方式,要做到這一點,它需要創建一個未使用的變量。我是否應該返回一個序列,其中admin:check-collections-exists
是序列中的第一項,那麼後續處理是第二個元素?只是尋找標準的優雅方式來做到這一點。我的功能是:
declare function admin:add-collection-to-publication($pub-name, $collection-name)
{
(:does this publication have a COLLECTIONS element?:)
let $unnecessary-variable := admin:check-collections-exists($pub-name)
(:now go and do what this function does:)
return "do some other stuff then return"
};
declare function admin:check-collections-exists($pub-name)
{
if(fn:exists($pubs-node/pub:PUBLICATION[pub:NAME/text()=$pub-name]/pub:COLLECTIONS))
then
"exists"
else
xdmp:node-insert-child($pubs-node/pub:PUBLICATION[pub:NAME/text()=$pub-name],<pub:COLLECTIONS/>)
};
我經常使用'func()[0]'(或'func()[4000000000]'如果前者被優化掉了)來計算一些東西並忽略它的結果 – BeniBela
我在macloglogic文檔中看到xdmp:function,但看起來像你如果你的函數需要一個參數,仍然需要返回。 012quxquery版本「1.0-ml」; 讓$函數:= xdmp:功能(XS:QName的( 「FN:CONCAT」)) 回報 xdmp:申請($功能, 「你好」, 「世界」) =>世界你好 –