How to Concatenate (Join) Values from Several Rows in XSLT


Given you have the following XML as a source:

    <Row Username="user1"/>
    <Row Username="user2"/>
    <Row Username="user3"/>

You’re asked to provide the following output:

<Users>user1, user2, user3</Users>


Using xsl:for-each in an XSLT transformation provides the needed functionality:

<xsl:template match="Rows">
         <xsl:for-each select="Row">
                 <xsl:when test="position() = 1">
                     <xsl:value-of select="@Username"/>
                     <xsl:value-of select="', '"/>
                     <xsl:value-of select="@Username"/>
1 Like

There is a slite mistake in a XSLT transformation according to given XML source. The for-reach should be

<xsl:for-each select="Row">

Fixed. Thanks a lot.