In XSLT 2.0:
<xsl:for-each-group select="account" group-by="nr">
XSLT 1.0 is considerably harder, you'll need to look up how to use Muenchian grouping.
In both cases you'll get a speed-up by defining a key to speed the lookup of transfer elements.
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference