【问题标题】:Include XQuery result through include in MarkLogic通过包含在 MarkLogic 中包含 XQuery 结果
【发布时间】:2018-10-12 10:26:07
【问题描述】:

我们可以通过任何方式将 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"))

对此的任何帮助将不胜感激。

【问题讨论】:

    标签: nosql xquery marklogic marklogic-8


    【解决方案1】:

    在 XQuery 中,XML 文字可以包含内联表达式的结果。

    此类表达式可以包括对xdmp:invoke() 的调用。

    因此,类似于以下未测试示例的代码应该可以工作(如果您使用的是 MarkLogic 8,则将外部变量映射的 MarkLogic 9 语法替换为 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
        )
    

    顺便说一句,从同一个事务中返回插入的文档比在单独的事务中读取文档更有效。如果插入失败,事务将不会返回文档,因此在单独的事务中读取并不能提供更大的保证。

    希望对您有所帮助,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      相关资源
      最近更新 更多