So I have an interesting problem, assume I have this document (example.xml) inside a MarkLogic database:
<Enrolls>
<Enroll>
<Status> Active </Status>
<boom> boom2 </boom>
</Enroll>
<Enroll>
<Status> Active </Status>
<boom> boom </boom>
</Enroll>
<Enroll>
<Status> Inactive </Status>
<boom> boom </boom>
</Enroll>
</Enrolls>
I want to replace all the "Active" Enroll elements with one node, so essentially my end result for this should be:
<Enrolls>
<boom> boom for the actives </boom>
<Enroll>
<Status> Inactive </Status>
<boom> boom </boom>
</Enroll>
</Enrolls>
To get this done, this is the code I wrote:
xdmp:node-replace((doc("example.xml")/Enrolls/Enroll[Status eq " Active "]), <boom> boom for the actives </boom>)
But this is the result I get:
<Enrolls>
<boom> boom for the actives </boom>
<boom> boom for the actives </boom>
<Enroll>
<Status> Inactive </Status>
<boom> boom </boom>
</Enroll>
</Enrolls>
The code replaces each active enroll with the same node I specified to replace. I want it to replace both the nodes at the same time with only one node. How can I do that and get the result I want?