I want to transform my custom XML to csv by using ";" as value delimiter. Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<root>
<operators>
<item>
<lfbis>1234567</lfbis>
<name>Stefan Maier</name>
<company />
<street>Testweg 7</street>
<citycode>95131</citycode>
<city>Hof</city>
<controlbody>BIKO</controlbody>
<productdata>
<item>Rinder</item>
<item>9</item>
</productdata>
</item>
<item>
<lfbis>5671234</lfbis>
<name>Antom Mueller</name>
<company>Berghof</company>
<street>Testweg 8</street>
<citycode>95111</citycode>
<city>Bamberg</city>
<controlbody>BIKO</controlbody>
<productdata>
<item>Rinder</item>
<item>9</item>
</productdata>
</item>
</operators>
</root>
I have managed so far (using the stackoverflow thread XML to CSV Using XSLT, especially using the code wrote by @Tomalak in his answer ...a version with configurable parameters that you can set programmatically) to use the following xslt transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:param name="delim" select="';'" />
<xsl:param name="quote" select="'"'" />
<xsl:param name="break" select="'
'" />
<xsl:template match="/">
<xsl:apply-templates select="root/operators/item" />
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates />
<!--<xsl:if test="following-sibling::*">-->
<xsl:value-of select="concat($delim, $break)" />
<!--</xsl:if>-->
</xsl:template>
<xsl:template match="*">
<xsl:value-of select="normalize-space()" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
... and I am getting the following result using xsltproc:
1234567;Stefan Maier;;Testweg 7;95131;Hof;BIKO;Rinder 9;
5671234;Antom Mueller;Berghof;Testweg 8;95111;Bamberg;BIKO;Rinder 9;
Now, what I am trying to achieve is that the item subelements of the productdata element be treated also as values in the csv result. So I need a ";" instead of " " (space) between the values Rinder and 9, such as my csv would look like:
1234567;Stefan Maier;;Testweg 7;95131;Hof;BIKO;Rinder;9;
5671234;Antom Mueller;Berghof;Testweg 8;95111;Bamberg;BIKO;Rinder;9;