What I want to get is a XSLT template to turn several XML element values into a coma separated string to be the value of a single output element.
I have found several examples in tutorials to do so for text output, but nothing for XML output.
Sample input:
<People>
<Person>John</Person>
<Person>Paul</Person>
<Person>George</Person>
<Person>Ringo</Person>
</People>
Desired output:
<Output>
<People>John,Paul,George,Ringo</People>
</Output>
This is what I got so far:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:element name="Output">
<xsl:element name="People">
<xsl:for-each select="People/Person">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
But I don`t know how to get rid of the last coma using this approach. Any ideas?
This should work:
Note: This will not produce CSV with quotes around each value.