【发布时间】:2013-01-03 14:12:30
【问题描述】:
使用 MarkLogic Xquery,我有一个函数 (admin:add-collection-to-publication),它调用另一个维护函数 ( admin:check-collections-exists),它检查元素的存在,如果它不存在,则创建该特定元素。
我调用维护函数的方式是使用 let。这似乎是一种奇怪的方式,要做到这一点,它需要创建一个未使用的变量。我是否应该返回一个序列,调用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],如果前者被优化掉)来计算一些东西并忽略它的结果 -
我在 marklogic 文档中看到 xdmp:function 但如果您的函数带有参数,您似乎仍然需要返回。 xquery 版本“1.0-ml”;让 $function := xdmp:function(xs:QName("fn:concat")) 返回 xdmp:apply($function, "hello", "world") => hello world