You can use for-each-group
to group the person
elements, and the separator
attribute on value-of
to build the comma-separated value:
<xsl:for-each-group select="person" group-by="name">
<person>
<xsl:sequence select="name" /><!-- copy the name element -->
<account>
<xsl:value-of select="current-group()/account" separator="," />
</account>
</person>
</xsl:for-each-group>
(assuming your current context node is the parent of the person
elements - if it is not then you'll have to adjust the for-each-group
select
expression appropriately)