Thank you Christian and Graydon! I've got a solution working by calling the script multiple times to do only a subset of the updates each time. On a different (though related) note, do I understand correctly that I should run a "db:optimize($db)" after each time I perform a significant amount of updates?
It’s definitely advisable if you perform queries that take advantage of the BaseX index structures – which is already the case for root/element[@id = $se/@id]. If the UPDINDEX option is enabled, the index structures will always be kept up-to-date (but again, a database optimization might be recommendable to minimize the index structures).