Jump to content

Concat Fields together to alter output


keevil

Recommended Posts

Im trying to contact fields together. The input file will look like this:

<?xml version="1.0" encoding="UTF-8"?><payloads>    <payload>	    <firstname>michael</firstname>	    <secondname>brown</secondname>	    <number>1</number>    </payload>    <payload>	    <firstname>michael</firstname>	    <secondname>brown</secondname>	    <number>2</number>    </payload>    <payload>	    <firstname>michael</firstname>	    <secondname>brown</secondname>	    <number>3</number>    </payload></payloads>

And i would like the output to look like this:

<?xml version="1.0" encoding="UTF-8"?><payloads>    <payload>	    <firstname>michael</firstname>	    <secondname>brown</secondname>	    <number>1,2,3</number>    </payload></payloads>

Can anyone help?

Link to comment
Share on other sites

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">    <xsl:output method="xml" indent="yes"/>       <xsl:key name="k" match="payload" use="firstname"/>       <xsl:template match="/payloads">	    <xsl:copy>		    <xsl:apply-templates select="payload[generate-id() =			    generate-id(key('k', firstname))]"/>	    </xsl:copy>    </xsl:template>       <xsl:template match="payload">	    <xsl:copy>		    <xsl:copy-of select="firstname"/>		    <xsl:copy-of select="secondname"/>		    <number>			    <xsl:for-each select="key('k', firstname)">				    <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:stylesheet>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...