MarkLogic单时态文档插入时设置版本URI报错求助
问题解决:XDMP-UNDVAR: Undefined variable $root
错误原因分析
报错提示变量$root未定义,核心是代码存在两处写法问题导致XQuery解析器无法正确识别$root的绑定:
- XML构造器中嵌入函数调用未用大括号:
<system-Start>(fn:current-time())</system-Start>会被解析为纯文本,而非执行函数获取当前时间,可能引发解析器对整个$root绑定表达式的误判; return后的多个更新表达式未明确包裹为序列,导致解析器对变量作用域的识别出现偏差。
修正后的代码
xquery version "1.0-ml"; import module namespace temporal = "http://marklogic.com/xdmp/temporal" at "/MarkLogic/temporal.xqy"; let $root := <EDILogFile> <ID>1234578</ID> <SystemRef>12344</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>false</Fail> <ManyReasons/> <SubmissionUser>System</SubmissionUser> <InternalBusinessUnit>Finance</InternalBusinessUnit> <Direction>Inbound</Direction> </EDILogFile> return ( temporal:statement-set-document-version-uri("EDI_22000043.xml","EDI_22000043.v1.xml"), temporal:document-insert("UnitemporalColl-SysAxesInDoc", "EDI_22000043.xml", $root) )
修改说明
- 将
<system-Start>(fn:current-time())</system-Start>改为<system-Start>{fn:current-time()}</system-Start>:用大括号包裹函数调用,确保执行fn:current-time()并将结果作为元素内容; - 用括号包裹
return后的两个更新函数:明确将两个表达式作为一个序列返回,避免解析器对变量作用域的误判,确保$root能被正确识别。
内容的提问来源于stack exchange,提问作者Rashmita Purkayastha
相关产品推荐
相关产品推荐

