This content has been marked as final.
Show 1 reply
-
1. Re: How do convert xml to csv in camel
bharadwaj Apr 25, 2015 3:30 AM (in response to szarekar)<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src/xmldata?noop=true"/>
<to uri="xslt:file:src/main/fruits.xslt"/>
<to uri="file://TESTOUT?fileName=output.csv"/>
</route>
</camelContext>sample xml file in src/xmldata folder
<AllFruits xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- All fruits below. -->
<Fruit>
<FruitId>Bannana</FruitId>
<FruitColor>Yellow</FruitColor>
<FruitShape>Moon</FruitShape>
<Customer>
<Name>Joe</Name>
<NumberEaten>5</NumberEaten>
<Weight>2.6</Weight>
</Customer>
<Customer>
<Name>Mark</Name>
<NumberEaten>8</NumberEaten>
<Weight>5.0</Weight>
</Customer>
</Fruit>
</AllFruits>src/main/fruits.xslt
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" encoding="ISO-8859-1" />
<xsl:variable name="newline" select="'
'"/>
<xsl:template match="Fruit">
<xsl:for-each select="Customer">
<xsl:value-of select="preceding-sibling::FruitId" />
<xsl:text>,</xsl:text>
<xsl:value-of select="NumberEaten" />
<xsl:text>,</xsl:text>
<xsl:value-of select="Weight" />
<xsl:value-of select="$newline" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>