I want to delete multiple nodes from document using a loop and hold the updated doc in memory using in-memory-update api. Below is the code I am using:
var mem = require("/MarkLogic/appservices/utils/in-mem-update.xqy");
var myDoc = cts.doc("abc.xml");
var nodeArr = [];
nodeArr = myDoc.xpath("/document/version").toArray();
for (i in nodeArr)
{
if(nodeArr[i].xpath('@id')!= "1"){
myDoc = mem.nodeDelete(nodeArr[i])
}
}
myDoc;
Let's say I have 3 versions in my document and I want to delete versions other than id=1
. Result of below code is only deleting version 3 and keeping version 2 still in the document. Maybe version 2 deletion is overridden by version 3 in memory.
What am I missing here?