[rrd-users] Here is my XSL to transform "rrdtool xport" output to CSV

Con Zyor conzyor34 at gmail.com
Fri Jan 9 23:07:41 CET 2009


Here is the xsl I use to transform "rrdtool xport" output to CSV.

This works with rrdtool 1.2 but rrdtool 1.3 xport presently spits out
invalid XML which breaks most stylsheet processors.

The only problem is that Excel doesn't understand "seconds since the
epoch."  Does anyone know how to transform "seconds since the epoch" to a
date format Excel will understand, using pure XSL only?

I used xsltproc linux command-line.  I have not tried others.  Please send
feedback.

<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- This makes xsltproc skip the xml headers, for parsing xml into flat
text -->
<xsl:output method="text" version="1.0" encoding="iso-8859-1" indent="no"/>

<xsl:template match="/">
  <xsl:text>"Timestamp",</xsl:text>
  <xsl:for-each select="xport/meta/legend/entry">
      <xsl:text>"</xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>"</xsl:text>
      <xsl:if test="position()!=last()">
        <xsl:text>,</xsl:text>
      </xsl:if>
  </xsl:for-each>
  <xsl:text>&#10;</xsl:text>
  <xsl:for-each select="xport/data/row">

      <xsl:text>"</xsl:text>
      <xsl:value-of select="t"/>
      <xsl:text>"</xsl:text>
      <xsl:text>,</xsl:text>

      <xsl:for-each select="v">
          <xsl:text>"</xsl:text>

          <!-- replace NaN with blank -->

          <xsl:if test=". != 'NaN'">
            <xsl:value-of select="."/>
          </xsl:if>

          <xsl:text>"</xsl:text>
          <xsl:if test="position()!=last()">
            <xsl:text>,</xsl:text>
          </xsl:if>
      </xsl:for-each>

      <xsl:text>&#10;</xsl:text>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.oetiker.ch/pipermail/rrd-users/attachments/20090109/f6da33d4/attachment.html 


More information about the rrd-users mailing list