nosql - 通过包含在 MarkLogic 中包含 XQuery 结果
问题描述
我们可以通过任何方式将 XQuery 结果包含在 XML 文档中,就像我们包含其他文档或 XPath 一样。
例如:
xquery version "1.0-ml";
declare namespace xi="http://www.w3.org/2001/XInclude";
xdmp:document-insert("/test1.xml", <document>
<p>This is a sample document.</p>
<xi:include href="test2.xml"/>
</document>);
xquery version "1.0-ml";
import module namespace xinc="http://marklogic.com/xinclude" at "/MarkLogic/xinclude/xinclude.xqy";
xinc:node-expand(fn:doc("/test1.xml"))
可以这样做如下:
xquery version "1.0-ml";
declare namespace xi="http://www.w3.org/2001/XInclude";
xdmp:document-insert("/test1.xml", <document>
<p>This is a sample document.</p>
<xi:include href="test2.xqy?var1=Hello&var2=world/>
</document>);
xquery version "1.0-ml";
import module namespace xinc="http://marklogic.com/xinclude" at "/MarkLogic/xinclude/xinclude.xqy";
xinc:node-expand(fn:doc("/test1.xml"))
对此的任何帮助将不胜感激。
解决方案
Within XQuery, an XML literal can include the result of an inline expression.
Such expressions can include a call to xdmp:invoke()
.
As a result, code similar the following untested example should work (replacing the MarkLogic 9 syntax for the external variables map with the MarkLogic 8 equivalent if you're on MarkLogic 8):
let $doc :=
<document>
<p>This is a sample document.</p>
{xdmp:invoke("test2.xqy",
map:entry("var1","Hello")
=> map:with("var2", "world")
)}
</document>
return (
xdmp:document-insert("/test1.xml", $doc),
$doc
)
By the way, it's more efficient to return the inserted document from the same transaction than to read the document in a separate transaction. If the insertion fails, the transaction won't return the document, so reading in a separate transaction provides no greater assurance.
Hoping that helps,
推荐阅读
- npm-install - npm install -s 是什么意思?
- qt - 在 QML 中,如何创建一个父组件,该组件接受子组件实例并将它们放在父组件层次结构中?
- machine-learning - 如何将语音文件输入 RNN/LSTM 进行语音识别?
- javascript - 如何使 JS/Jquery 透视效果在模态中起作用?
- postgresql - 尽管使用了 NOT NULL 和 <> '',但仍出现空白行
- python-3.x - 在 route_id on-change 方法中创建销售订单行
- laravel - 在 Laravel 5 中限制文本列字符
- php - 使用“echo $image;”之间的有效区别是什么?和“回声 $image->getImageBlob();”
- python - IndexError:只有整数、切片(`:`)、省略号(`...`)
- c# - 发送ref参数时如何返回out参数?