0008 How to Convert XML into CSV

A practical Advanced ETL Processor example for building, testing, and adapting one automation workflow.

Advanced ETL Processor
4.9 ★★★★★ Based on 16 reviews on Capterra See all reviews on Capterra →

Use this example to build one working automation package, test it safely, and then adapt it to your own files, folders, or data rules. Start small. Automation is helpful; automated mistakes are just faster mistakes.

This Example Demonstrates how to convert multiple XML files into CSV files

Here is an XML source example


                    <Table>
<Record>
<ID>1</ID>
<Company>James Bond Production</Company>
<Amount>13</Amount>
</Record>
<Record>
<ID>2</ID>
<Company>Green Cloud</Company>
<Amount>14</Amount>
</Record>
</Table>
                  

Here is XSLT used transformation:


                    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="Table">
<xsl:text>ID,Company,Amount</xsl:text>
<xsl:text>&#xA;</xsl:text>
<xsl:for-each select="Record">
<xsl:value-of select="ID"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="Company"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="Amount"/>
<xsl:text>&#xA;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
                  

Notes: We kept XSLT simple so it is easy to understand and modify if necessary.

Steps to follow

  • Download and install Advanced ETL Processor [Link]
  • Download and Unzip example [Link]
  • Create a new transformation and open the .ats file

Convert multiple XML files into CSV format

  • Double click on the reader and select source XML Directory

XML Data Reader

  • Repeat the process for the data writer
  • Press the green arrow to run the transformation

How it works

  1. Data Reader scans the source directory and loads files into memory one by one
  2. The transformer converts files in memory into CSV using XSLT
  3. Data Writer writes results into the target directory
  • To amend the transformation double click on it

The transformation uses XML XSLT Transformation Function to convert XML to CSV and it also changes file name extension

ETL Data Transformer

  • To change XML XSLT Transformation Function properties double click on it.

XML Example

  • Amend XSLT Transformation if necessary

XSLT Editor

  • Press transform to see the result

XSLT Transformation Result

Related Advanced ETL Processor resources

For more automation examples, review the Advanced ETL Processor tutorials, read the WIKI, or download the Advanced ETL Processor Enterprise trial.