i am trying to filter on a specific field and concat on another field:
Input:
&
Use this template:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="k" match="payload" use="concat(firstname, '|', secondname)"/>
<xsl:template match="payload[generate-id() =
generate-id(key('k', concat(firstname, '|', secondname)))]">
<xsl:copy>
<xsl:copy-of select="firstname"/>
<xsl:copy-of select="secondname"/>
<number>
<xsl:for-each select="key('k', concat(firstname, '|', secondname))">
<xsl:value-of select="number"/>
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</number>
</xsl:copy>
</xsl:template>
<xsl:template match="payload"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
When applied to provided input XML, it outputs wanted correct result:
<payloads>
<payload>
<firstname>michael</firstname>
<secondname>brown</secondname>
<number>1,2,3</number>
</payload>
</payloads>