Good Morning Charles,


this sounds like a case for the 'transform' expression which is part of XQuery Update. 

The transform expression modifies a copy of nodes without touching the original nodes / making permanent changes to your database. I'm sorry for our documentation not being clear about this. We are working on that.


Taking your query as a start ...

for $x in /data/templates/template[id='123']/content/*
for $y in /data/pages/page[id='456']/content/*
return $x

for $x in /data/templates/template[id='123']/content/*
for $y in /data/pages/page[id='456']/content/*
return ( 
copy $c := $x
modify replace node $c/body/text with $y
return $c
)

... should do the trick. 


Also, I'd like to be able to do this recursively. Is that possible? Do I have to write my own function for this?

Sorry - I'm not sure what you mean here. But if you provide me with further details (i.e. a larger document snippet or more details about your use case) I'd be happy to help you with that.


Cheers,
Lukas