Hi all,
I have some xml in the following format:
<fileExport>
<rows>
<row id="0">
<columns>
<column id="0">
<name>Date Time</name>
<value>2010-10-2 23:00:00 GMT</value>
</column>
<column id="1">
<name>Primary</name>
<value>100.1</value>
</column>
<column id="2">
<name>Manual</name>
<value>20.5</value>
</column>
...
</columns>
</row>
<row id="1">
<columns>
<column id="0">
<name>Date Time</name>
<value>2010-10-3 00:00:00 GMT</value>
</column>
<column id="1">
<name>Primary</name>
<value>110.5</value>
</column>
...
<column id="2">
<name>Manual</name>
<value>23.1</value>
</column>
</columns>
</row>
</rows>
</fileExport>
Now the idea is to transform this to CSV text. Everything seems to be working fine - but I have 32 columns for each row in the above. To transform this to CSV, I am using the following XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:for-each select="//rows/row">
<!-- Now add a new row for each column -->
<!-- first row in file for this row in table -->
<xsl:text>A</xsl:text>
<xsl:text>,</xsl:text>
<xsl:value-of select="columns/column[name='Date Time']/value"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="columns/column[name='Primary']/value"/>
<xsl:text>,</xsl:text>
<xsl:text>P</xsl:text>
<xsl:text>
</xsl:text>
<!-- second row in file for this row in table -->
<xsl:text>A</xsl:text>
<xsl:text>,</xsl:text>
<xsl:value-of select="columns/column[name='Date Time']/value"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="columns/column[name='Manual']/value"/>
<xsl:text>,</xsl:text>
<xsl:text>M</xsl:text>
<xsl:text>
</xsl:text>
... now repeat for the next 30 columns ...
<!-- next row in table-->
</xsl:for-each>
<xsl:text><EOF></xsl:text>
</xsl:template>
</xsl:stylesheet>
Now that gives us the output:
A,2010-10-2 23:00:00 GMT,100.1,P
A,2010-10-2 23:00:00 GMT,20.5,M
A,2010-10-3 00:00:00 GMT,110.5,P
A,2010-10-3 00:00:00 GMT,23.1,M
<EOF>
Question is, having 32 or so columns in the XML is it possible to shorten the XSL required to achieve the same results?
Any ideas?
Thanks,
Andez