aboutsummaryrefslogtreecommitdiffstats
path: root/xslt/xml2csv.xslt
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2014-03-02 01:17:32 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-02 12:04:15 -0800
commitb7940dec5c7839eb3a315baf5f5248b45c8c5f9a (patch)
tree85cdd62fe67851a42cb54fc5c32eda1664edd828 /xslt/xml2csv.xslt
parent3df506b081cbd38663b9f84efed1ab136b19b246 (diff)
downloadsubsurface-b7940dec5c7839eb3a315baf5f5248b45c8c5f9a.tar.gz
XSLT to export dive log in CSV
This implements divelog export into CSV format. This currently supports only metric units and lacks user interface. See #434 Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'xslt/xml2csv.xslt')
-rw-r--r--xslt/xml2csv.xslt51
1 files changed, 51 insertions, 0 deletions
diff --git a/xslt/xml2csv.xslt b/xslt/xml2csv.xslt
new file mode 100644
index 000000000..f647537df
--- /dev/null
+++ b/xslt/xml2csv.xslt
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:strip-space elements="*"/>
+ <xsl:output method="text" encoding="UTF-8"/>
+
+ <xsl:variable name="fs">,</xsl:variable>
+
+ <xsl:template match="/divelog/dives">
+ <xsl:value-of select='concat("dive number", $fs, "dive date", $fs, "dive time", $fs, "time", $fs, "depth", $fs, "temperature", $fs, "pressure")'/>
+ <xsl:text>
+</xsl:text>
+ <xsl:apply-templates select="dive|trip/dive"/>
+ </xsl:template>
+
+ <xsl:template match="dive">
+ <xsl:variable name="number">
+ <xsl:value-of select="@number"/>
+ </xsl:variable>
+ <xsl:variable name="date">
+ <xsl:value-of select="@date"/>
+ </xsl:variable>
+ <xsl:variable name="time">
+ <xsl:value-of select="@time"/>
+ </xsl:variable>
+ <xsl:for-each select="divecomputer/sample|sample">
+ <xsl:value-of select="concat('&quot;', $number, '&quot;')"/>
+ <xsl:value-of select="$fs"/>
+ <xsl:value-of select="concat('&quot;', $date, '&quot;')"/>
+ <xsl:value-of select="$fs"/>
+ <xsl:value-of select="concat('&quot;', $time, '&quot;')"/>
+ <xsl:value-of select="$fs"/>
+ <xsl:value-of select="concat('&quot;', substring-before(@time, ' '), '&quot;')"/>
+ <xsl:value-of select="$fs"/>
+ <xsl:value-of select="concat('&quot;', substring-before(@depth, ' '), '&quot;')"/>
+
+ <xsl:value-of select="$fs"/>
+ <xsl:if test="@temp != ''">
+ <xsl:value-of select="concat('&quot;', substring-before(@temp, ' '), '&quot;')"/>
+ </xsl:if>
+
+ <xsl:value-of select="$fs"/>
+ <xsl:if test="@pressure != ''">
+ <xsl:value-of select="concat('&quot;', substring-before(@pressure, ' '), '&quot;')"/>
+ </xsl:if>
+
+ <xsl:text>
+</xsl:text>
+ </xsl:for-each>
+ </xsl:template>
+
+</xsl:stylesheet>