summaryrefslogtreecommitdiffstats
path: root/xslt/SuuntoSDM.xslt
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2011-11-16 07:12:44 +0200
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-11-21 11:33:52 -0800
commit61f3114fce0c188b989270a33e476db52b81e810 (patch)
tree1439726ad742cdf2e7f66373676734eb90ebe54f /xslt/SuuntoSDM.xslt
parent5a046d94ea808963b5e6a5d740d360815b0def6d (diff)
downloadsubsurface-61f3114fce0c188b989270a33e476db52b81e810.tar.gz
XSLT to import SDM dive log
This is tested with Linus' sample data, all basic functionality seems to be working properly. Gas changes are implemented but not tested as there was no samples of those. Multiple cylinders are missing because there was no samples available. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'xslt/SuuntoSDM.xslt')
-rw-r--r--xslt/SuuntoSDM.xslt245
1 files changed, 245 insertions, 0 deletions
diff --git a/xslt/SuuntoSDM.xslt b/xslt/SuuntoSDM.xslt
new file mode 100644
index 000000000..45c151209
--- /dev/null
+++ b/xslt/SuuntoSDM.xslt
@@ -0,0 +1,245 @@
+<?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="xml" indent="yes"/>
+
+ <xsl:template match="/">
+ <dives>
+ <program name="subsurface" version="1"/>
+ <xsl:apply-templates select="/SUUNTO/MSG"/>
+ </dives>
+ </xsl:template>
+
+ <xsl:template match="MSG">
+ <xsl:variable name="units" select="'si'"/>
+
+ <dive number="{DIVENUMBER}">
+ <xsl:attribute name="date">
+ <xsl:call-template name="dateConvert">
+ <xsl:with-param name="date" select="DATE"/>
+ </xsl:call-template>
+ </xsl:attribute>
+
+ <xsl:attribute name="time">
+ <xsl:value-of select="TIME"/>
+ </xsl:attribute>
+
+ <xsl:attribute name="duration">
+ <xsl:call-template name="timeConvert">
+ <xsl:with-param name="timeSec" select="DIVETIMESEC"/>
+ <xsl:with-param name="units" select="$units"/>
+ </xsl:call-template>
+ </xsl:attribute>
+
+ <xsl:choose>
+ <xsl:when test="MEANDEPTH != ''">
+ <depth max="{concat(MAXDEPTH,' m')}" mean="{concat(MEANDEPTH, ' m')}"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <depth max="{concat(MAXDEPTH,' m')}"/>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <temperature air="{concat(AIRTEMP, ' C')}" water="{concat(WATERTEMPATEND, ' C')}"/>
+ <xsl:if test="SURFACETIME != '0'">
+ <surfacetime>
+ <xsl:call-template name="timeConvert">
+ <xsl:with-param name="timeSec" select="SURFACETIME" />
+ <xsl:with-param name="units" select="$units" />
+ </xsl:call-template>
+ </surfacetime>
+ </xsl:if>
+ <divemaster><xsl:value-of select="DIVEMASTER" /></divemaster>
+ <buddy><xsl:value-of select="PARTNER" /></buddy>
+ <xsl:choose>
+ <xsl:when test="LOCATION != ''">
+ <location><xsl:value-of select="normalize-space(concat(LOCATION, ' ' , SITE))" /></location>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="SITE != ''">
+ <location><xsl:value-of select="SITE" /></location>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ <xsl:if test="LOGNOTES != ''">
+ <xsl:value-of select="LOGNOTES" />
+ </xsl:if>
+
+<!-- FIXME: add support for multiple cylinders, need sample data -->
+ <cylinder>
+ <xsl:attribute name="o2">
+ <xsl:choose>
+ <xsl:when test="O2PCT != ''">
+ <xsl:value-of select="concat(O2PCT, '%')"/>
+ </xsl:when>
+ <xsl:otherwise>21.0%</xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+ <xsl:if test="HEPCT != ''">
+ <xsl:attribute name="he">
+ <xsl:value-of select="concat(HEPCT, '%')"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="CYLINDERSIZE != ''">
+ <xsl:attribute name="size">
+ <xsl:choose>
+ <xsl:when test="CYLINDERWORKPRESSURE = '0'">
+ <xsl:value-of select="concat(CYLINDERSIZE, ' l')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="cuft2l">
+ <xsl:with-param name="size" select="CYLINDERSIZE"/>
+ <xsl:with-param name="pressure" select="CYLINDERWORKPRESSURE"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:attribute name="start">
+ <xsl:variable name="number" select="CYLINDERSTARTPRESSURE"/>
+ <xsl:call-template name="pressure">
+ <xsl:with-param name="number" select="$number"/>
+ <xsl:with-param name="units" select="$units"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ <xsl:attribute name="end">
+ <xsl:variable name="number" select="CYLINDERENDPRESSURE"/>
+ <xsl:call-template name="pressure">
+ <xsl:with-param name="number" select="$number"/>
+ <xsl:with-param name="units" select="$units"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ <xsl:if test="CYLINDERWORKPRESSURE != '0'">
+ <xsl:attribute name="workpressure">
+ <xsl:variable name="number" select="CYLINDERWORKPRESSURE"/>
+ <xsl:call-template name="pressure">
+ <xsl:with-param name="number" select="$number"/>
+ <xsl:with-param name="units" select="$units"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xsl:if>
+ </cylinder>
+
+ <!-- DELTA is the sample interval -->
+ <xsl:variable name="delta">
+ <xsl:choose>
+ <xsl:when test="SAMPLEINTERVAL != ''">
+ <xsl:value-of select="SAMPLEINTERVAL"/>
+ </xsl:when>
+ <xsl:otherwise>0</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <!-- end delta -->
+
+ <!-- gas change -->
+<!-- FIXME: test this with proper data -->
+ <xsl:for-each select="GASCHANGE">
+ <xsl:if test="MIXTIME != '0'">
+ <event name="gaschange">
+ <xsl:attribute name="value">
+ <xsl:value-of select="MIXVALUE" />
+ </xsl:attribute>
+ <xsl:attribute name="time">
+ <xsl:call-template name="timeConvert">
+ <xsl:with-param name="timeSec" select="MIXTIME"/>
+ <xsl:with-param name="units" select="'si'"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </event>
+ </xsl:if>
+ </xsl:for-each>
+ <!-- end gas change-->
+
+ <!-- dive sample - all the depth and temp readings -->
+ <xsl:for-each select="SAMPLE">
+ <xsl:choose>
+ <xsl:when test="BOOKMARK = ''">
+ <sample>
+ <xsl:attribute name="time">
+ <xsl:call-template name="timeConvert">
+ <xsl:with-param name="timeSec" select="SAMPLETIME"/>
+ <xsl:with-param name="units" select="'si'"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ <xsl:attribute name="depth">
+ <xsl:value-of select="concat(DEPTH, ' m')"/>
+ </xsl:attribute>
+ <xsl:attribute name="temp">
+ <xsl:value-of select="TEMPERATURE"/>
+ </xsl:attribute>
+ <xsl:attribute name="pressure">
+ <xsl:call-template name="pressure">
+ <xsl:with-param name="number" select="PRESSURE"/>
+ <xsl:with-param name="units" select="$units"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </sample>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="BOOKMARK != 'Surface'">
+ <event name="{BOOKMARK}">
+ <xsl:attribute name="time">
+ <xsl:call-template name="timeConvert">
+ <xsl:with-param name="timeSec" select="SAMPLETIME"/>
+ <xsl:with-param name="units" select="'si'"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </event>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <!-- dive sample -->
+
+ </dive>
+ </xsl:template>
+ <!-- end JDive -->
+
+ <!-- convert pressure to bars -->
+ <xsl:template name="pressure">
+ <xsl:param name="number"/>
+ <xsl:param name="units"/>
+
+ <xsl:choose>
+ <xsl:when test="$number != ''">
+ <xsl:value-of select="concat(($number div 1000), ' bar')"/>
+ </xsl:when>
+ <xsl:otherwise>0</xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <!-- end convert pressure -->
+
+ <!-- convert cuft to liters-->
+ <xsl:template name="cuft2l">
+ <xsl:param name="size"/>
+ <xsl:param name="pressure"/>
+ <xsl:value-of select="concat(format-number((($size*28.3168466) div ($pressure div 1013.25)), '0.000'), ' l')" />
+ </xsl:template>
+ <!-- end cuft2l -->
+
+ <!-- convert time in seconds to minutes:seconds -->
+ <xsl:template name="timeConvert">
+ <xsl:param name="timeSec"/>
+ <xsl:param name="units"/>
+
+ <xsl:choose>
+ <xsl:when test="$timeSec = '0'">
+ <xsl:value-of select="'0:00 min'" />
+ </xsl:when>
+ <xsl:when test="$units = 'si'">
+ <xsl:value-of select="concat(floor(number($timeSec) div 60), ':', format-number(floor(number($timeSec) mod 60), '00'), ' min')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="concat(substring-before($timeSec, '.'), ':', format-number(substring-after($timeSec, '.'), '00'), ' min')"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+ <!-- end convert time -->
+
+ <!-- convert date from dotted notation to dash notation -->
+ <xsl:template name="dateConvert">
+ <xsl:param name="date" />
+ <xsl:value-of select="concat(substring($date,7,4), '-', substring($date,4,2), '-', substring($date,1,2))" />
+ </xsl:template>
+</xsl:stylesheet>