I am trying the below xquery to add the field value from the xml field - SystemRef which is set in the variable root.
I wanted to see the version of the document as - EDI_22000043.xml_2022-11-29T13:59:00.739688Z
But I am getting the result as this - EDI_.xml_2022-11-29T14:10:28.466401Z
Xquery :
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/EDILogFile/SystemRef/text(),".","xml","_",fn:current-dateTime()))),
temporal:document-insert("UnitemporalColl-SysAxesInDoc", "EDI_22000043.xml", $root)
)
Your
$root
variable is theEDILogFile
element, not a document. So, the context for an XPath is starting from theEDILogFile
element (you are "standing on" that element and it's immediate child isSystemRef
.If you select a document from the database you are "standing" on the
document-node()
and it's immediate child node would be theEDILogFile
element, and that XPath would work as expected. However, since you have let a local variable that is just an Element you need to make an adjustment.You should use the XPath:
$root/SystemRef/text()
instead of$root/EDILogFile/SystemRef/text()
.