You may be able to save lots of time if you manage to rewrite the XSLT script to XQuery (Update). Here’s a script that creates an element with 1 million nodes, which are immediately deleted again. It takes less than 1 second:
<a>{ (1 to 1000000) ! <b/> }</a> update {
delete node ./b
}