我有多个员工 xml 文档使用 doc uri (/employee/*.xml) 保存在 ML DB 中,我想从新 XML 中获取更新,其中唯一引用键是 roleID(在 ML XML 中它的 roleID 和在新 XML 中它是 newroleID )。每当找到匹配项时,它应该用新的 XMl 的 newFirstName 更新 ML xml 的 firstName 值,用 newlastName 更新 lastname 值,用新的 dep 更新 dep,xml 结构的其余部分应该保持不变。
Marklogic XML 结构如下:
doc uri /employee/1.xml
<employee>
<firstName>Jim</firstName>
<lastName>Day</lastName>
<dep>IT</dep>
<city>Boston</city>
<roleID>1111<roleID>
<internalID>2222</internalID>
</employee>
doc uri /employee/2.xml
<employee>
<firstName>Jan</firstName>
<lastName>Silly</lastName>
<dep>Finance</dep>
<city>DC</city>
<roleID>3333<roleID>
<internalID>4444</internalID>
</employee>
doc uri /employee/3.xml
<employee>
<firstName>Jack</firstName>
<lastName>John</lastName>
<dep>HR</dep>
<city>Virginia</city>
<roleID>5555<roleID>
<internalID>6666</internalID>
</employee>
我正在尝试这个但不确定如何更新文档,它似乎也没有优化 xquery,请帮助。
let $newXML := <employees>
<newemployee>
<NewfirstName>New Fname1</newfirstName>
<newlastName>New Lname1</newlastName>
<newdep>New Dep1</newdep>
<newcity>Boston</newcity>
<newroleID>1111<newroleID>
<internalID>2222</internalID>
</newemployee>
<newemployee>
<newfirstName>New Fname2</newfirstName>
<newlastName>New Lname</newlastName>
<newdep>New Dep</newdep>
<newcity>Boston</newcity>
<newroleID>5555<newroleID>
<newinternalID>6666</newinternalID>
</employee>
</employees>
for $oldXML in doc("/employee/*.xml")/employee
where $newXML/newemployee/newroleID eq $oldXML/roleID
return
for $Matched in $oldXML
return
let $finalXML :=
(: Not sure how to update some nodes in given URI, where rest of structure remain same :)
<employee>
<firstName>{$newXML/newemployee/newfirstName/text()}</firstName>
<lastName>{$newXML/newemployee/newlastName/text()}</lastName>
<dep>{$newXML/newemployee/newdep/text()}</dep>
</employee>