MarkLogic Xquery を使用して、要素の存在をチェックする(admin:add-collection-to-publication)
別のメンテナンス関数を呼び出す関数( admin:check-collections-exists)
があり、存在しない場合はその特定の要素を作成します。
私がメンテナンス機能を呼び出す方法は、letを使用することです。これは奇妙な方法のように思えます。これを行うには、未使用の変数を作成する必要があります。代わりに、シーケンスadmin:check-collections-exists
の最初の項目を呼び出してシーケンスを返し、その後の処理を 2 番目の要素にする必要がありますか? これを行うための標準的なエレガントな方法を探しています。私の機能は次のとおりです。
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/>)
};