I am trying to just convert any xml file to CSV format. the issue as when the xml has nested / child elements those values are not output as comma separated. i have tried lot of examples in other posts but none of them works out as needed. I am a beginner to XSLT any help to this very helpful.
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<trade>
<createdBy>1</createdBy>
<createdOnDate>2</createdOnDate>
<Payment>
<indicator>3</indicator>
<updateBy>4</updateBy>
</Payment>
<Parties>
<partyId>5</partyId>
<partyRoleTypeCode>6</partyRoleTypeCode>
</Parties>
<Product>
<term>7</term>
<shortDescription>8</shortDescription>
</Product>
</trade>
<trade>
<createdBy>10</createdBy>
<createdOnDate>20</createdOnDate>
<Payment>
<indicator>30</indicator>
<updateBy>40</updateBy>
</Payment>
<Parties>
<partyId>50</partyId>
<partyRoleTypeCode>60</partyRoleTypeCode>
</Parties>
<Product>
<term>70</term>
<shortDescription>80</shortDescription>
</Product>
</trade>
</S:Body>
</S:Envelope>
thanks OkieOth. I have tried the modified script but it produce the output as
1,2,3,4,5,6,7,8, ( i need to get rid of the last comma , looks keep this comma adding every row)
10,20,30,40,50,60,70,80
Please help. i need to get rid of the ending comma after last value of the every line. note:the comma get removed only for the last row.
<xsl:template match="//S:Body">
<xsl:apply-templates select="//trade"/>
</xsl:template>
<xsl:template match="trade">
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="//text()">
<xsl:copy-of select="." />
<xsl:choose>
<xsl:when test="(following::*)">
<xsl:value-of select="','"/>
</xsl:when>
</xsl:choose>
</xsl:template>
Try this one:
output:
You may also check my previous post at SOAP Response converting to CSV