You are here:   » Home » News » Archive » 01/06 XML2CSV

Output of ZMS data tables as CSV

Author: Diez B. Roggisch, Artnology; Dr. F. Hoffmann, SNTL Publishing, 2006/02/28

The abbreviation CSV (Character Separated Values, also Comma Separated Values) stands for a file format. A simply structured XML-code underlies the ZMS data table that can be transformed with DTML or XSLT to CSV. In this way ZMS data table contents can be transferred very easily to other database systems. The example shows the variant with XSLT.

[1] Presentation of the filter definition: the process only consists of one single XSL-transformation step; the result format is declared as "text".

Zoom (27KB)

[2] Filter definition in detail: the filter here is dedicated to the data table objects for literature, glossary and footnotes. The ZMS administrator gets authorisation for the export.

For the transformation a ZMS-filter is applied consisting of one single process step: per XSL the XML-stream generated by ZMS is converted into a CSV-stream. The corresponding XSL-code processes the list of dictionary elements acc. to the following instruction and line-by-line writes out the values separated by a vertical bar (Download):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:output method="text"/>
  <xsl:template match="//list">
    <xsl:for-each select="item">
      <xsl:apply-templates select="dictionary"/>
      <xsl:text>
</xsl:text>
    </xsl:for-each>
  </xsl:template>
  <xsl:template match="dictionary">
    <xsl:for-each select="item">
      <xsl:value-of select="text()"/>
      <xsl:if test="position() &lt; last()">
        <xsl:text>|</xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
  <!-- suppress unneeded textual content -->
  <xsl:template match="text()"/>
</xsl:stylesheet>

[3] As server-sided batch-process only a general call of the XSL-transformer (here xsltproc) is needed; the XSL-file is transferred to this process with the filter-definition (code see above).

[4] Use of the filter on a content node exemplified through a literature data table

[5] The output stream is given over directly to the browser. (Alternatively a Zip-file could be generated with another batch-step server-sided and given back.)