You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MarkLogic中使用document-version-uri拼接XML字段值失败问题

XQuery拼接文档版本URI问题解决

问题原因

你代码中获取SystemRef文本值的路径有误:

$root/EDILogFile/SystemRef/text()

$root变量本身就是<EDILogFile>元素,再通过$root/EDILogFile查找子节点会返回空序列,导致拼接时该位置无内容,最终生成EDI_.xml_...的结果。

修正后的代码

将路径改为直接从$root下获取SystemRef节点的文本值:

xquery version "1.0-ml";
import module namespace temporal = "http://marklogic.com/xdmp/temporal" 
    at "/MarkLogic/temporal.xqy";   
let $root := 
<EDILogFile>
    <ID>f1258d4ae0df43d5a1e05ce9139f0ed2</ID>
    <SystemRef>22000043</SystemRef>
  <system-Start>(fn:current-time())</system-Start>
  <system-End></system-End>
  <DateCreated>2022-09-09T19:07:46.3492849+01:00</DateCreated>
    <TimeSaved>240</TimeSaved>
    <Production>true</Production>
    <Partner>Ellerman</Partner>
    <MessageType>Invoice</MessageType>
    <Fail>true</Fail>
    <ManyReasons/>
    <SubmissionUser>System</SubmissionUser>
    <InternalBusinessUnit>Finance</InternalBusinessUnit>
    <Direction>Inbound</Direction>
</EDILogFile>
return (
temporal:statement-set-document-version-uri("EDI_22000043.xml", fn:concat("EDI", "_", $root/SystemRef/text(), ".xml", "_", fn:current-dateTime())),
temporal:document-insert("UnitemporalColl-SysAxesInDoc", "EDI_22000043.xml", $root)
)

额外优化

  • 简化fn:concat参数,让代码更简洁:
    fn:concat("EDI_", $root/SystemRef/text(), ".xml_", fn:current-dateTime())
    
  • 若需处理SystemRef节点不存在的情况,可添加默认值:
    fn:concat("EDI_", coalesce($root/SystemRef/text(), "unknown"), ".xml_", fn:current-dateTime())
    

内容的提问来源于stack exchange,提问作者Rashmita Purkayastha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 05:55:31