I was suggesting, instead of the following (which puts update within a loop)
for $signatory in collection(cmn:get-lex-db())/bu:ontology[@for='document']/bu:signatories/bu:signatory
let $user := collection(cmn:get-lex-db())/bu:ontology/bu:user[bu:userId eq $signatory/bu:userId][1]
let $user-uri := $user/@uri
let $user-name := concat($user/bu:lastName,", ",$user/bu:firstName)
return
(: safe-guarding multiple <bu:person/> nodes since 2012! :)
if (empty($signatory/bu:person)) then
update insert <bu:person isA="TLCPerson" href="{$user-uri}" showAs="{$user-name}" /> into $signatory
else
()
something like the following - which puts the data collation within the loop and the update statement is just a single one :
update insert
for $signatory in collection(cmn:get-lex-db())/bu:ontology[@for='document']/bu:signatories/bu:signatory
let $user := collection(cmn:get-lex-db())/bu:ontology/bu:user[bu:userId eq $signatory/bu:userId][1]
let $user-uri := $user/@uri
let $user-name := concat($user/bu:lastName,", ",$user/bu:firstName)
where empty($signatory/bu:person)
return <bu:person isA="TLCPerson" href="{$user-uri}" showAs="{$user-name}" />
into $signatory