Thanks for the background information.
But with XQuery's constraint on when you can do updates that's not possible, at least not in a naïve way--if you have a function that needs to return a result it cannot also do updating (meaning it can't call any updating functions).
I understand the reasoning for that restriction but it is an annoying constraint.
Indeed it is. The implementation of the XQuery Scripting Extension [1] would have been one way out, but due to its complexity, the Zorba guys were the only ones that ever implemented it. One other way would have been to ignore the constraints of the official specs, but we decided to stay compliant. One more solution – at least for your requirement to have updating functions that can return items – is our MIXUPDATES option (see [2] for more details).
Ironically, in our own code, we don't stumble across this restriction very often, probably because have already got used so much to the redirection pattern. Version 3.0 of the W3 XQuery Update Facility may provide a construct that will render our db:output extension obsolete.
Christian
[1] http://www.w3.org/TR/xquery-sx-10/ [2] http://docs.basex.org/wiki/Options#MIXUPDATES