subsurface/xslt/uddf.xslt
Miika Turkia 1668952ed3 Include more information on Aquadivelog import
This adds information on cylinders and gas changes and some other basic
stuff like buddy, dive site, weights.

Visibility should probably be ignored as UDDF specifies it as meters and
we have a scale of 0-5. But currently it is copied as is to the
visibility field in Subsurface.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-08 21:02:46 -07:00

386 lines
15 KiB
HTML

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:u="http://www.streit.cc/uddf/3.2/"
xmlns:u1="http://www.streit.cc/uddf/3.1/"
exclude-result-prefixes="u u1"
version="1.0">
<xsl:import href="commonTemplates.xsl"/>
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<divelog program="subsurface-import" version="2">
<settings>
<divecomputerid deviceid="ffffffff">
<xsl:choose>
<xsl:when test="/UDDF/history != ''">
<xsl:apply-templates select="/UDDF/history"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="/uddf/generator|/u:uddf/u:generator|/u1:uddf/u1:generator"/>
</xsl:otherwise>
</xsl:choose>
</divecomputerid>
</settings>
<dives>
<xsl:apply-templates select="/uddf/profiledata/repetitiongroup/dive|/u:uddf/u:profiledata/u:repetitiongroup/u:dive|/u1:uddf/u1:profiledata/u1:repetitiongroup/u1:dive|/UDDF/dive"/>
</dives>
</divelog>
</xsl:template>
<xsl:template match="generator|u:generator|u1:generator">
<xsl:if test="manufacturer/name|u:manufacturer/u:name|u1:manufacturer/u1:name != ''">
<xsl:attribute name="model">
<xsl:value-of select="name|u:name|u1:name"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="name|u:name|u1:name != ''">
<xsl:attribute name="firmware">
<xsl:value-of select="manufacturer/name|/u:manufacturer/u:name|/u1:manufacturer/u1:name"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="version|u:version|u1:version != ''">
<xsl:attribute name="serial">
<xsl:value-of select="version|u:version|u1:version"/>
</xsl:attribute>
</xsl:if>
</xsl:template>
<xsl:template match="modified">
<xsl:if test="application/name != ''">
<xsl:attribute name="model">
<xsl:value-of select="application/name"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="application/version != ''">
<xsl:attribute name="serial">
<xsl:value-of select="application/version"/>
</xsl:attribute>
</xsl:if>
</xsl:template>
<xsl:template match="gasdefinitions|u:gasdefinitions|u1:gasdefinitions|gas_def">
<xsl:for-each select="mix|u:mix|u1:mix|gas_mix">
<cylinder>
<xsl:attribute name="description">
<xsl:value-of select="name|u:name|u1:name|mixname"/>
</xsl:attribute>
<xsl:attribute name="o2">
<xsl:call-template name="gasConvert">
<xsl:with-param name="mix">
<xsl:value-of select="o2|u:o2|u1:o2"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="he">
<xsl:call-template name="gasConvert">
<xsl:with-param name="mix">
<xsl:value-of select="he|u:he|u1:he"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
</cylinder>
</xsl:for-each>
</xsl:template>
<xsl:template match="dive|u:dive|u1:dive">
<dive>
<!-- Count the amount of temeprature samples during the dive -->
<xsl:variable name="temperatureSamples">
<xsl:call-template name="temperatureSamples" select="samples/waypoint/temperature|u:samples/u:waypoint/u:temperature|u1:samples/u1:waypoint/u1:temperature|samples/t">
<xsl:with-param name="units" select="'Kelvin'"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="date != ''">
<xsl:attribute name="date">
<xsl:value-of select="concat(date/year,'-',format-number(date/month, '00'), '-', format-number(date/day, '00'))"/>
</xsl:attribute>
<xsl:attribute name="time">
<xsl:value-of select="concat(format-number(time/hour, '00'), ':', format-number(time/minute, '00'))"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="informationbeforedive/datetime|u:informationbeforedive/u:datetime|u1:informationbeforedive/u1:datetime != ''">
<xsl:call-template name="datetime">
<xsl:with-param name="value">
<xsl:value-of select="informationbeforedive/datetime|u:informationbeforedive/u:datetime|u1:informationbeforedive/u1:datetime"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
</xsl:choose>
<xsl:if test="dive_number != ''">
<xsl:attribute name="number">
<xsl:value-of select="dive_number"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="dive_duration != '' and dive_duration != 0">
<xsl:attribute name="duration">
<xsl:call-template name="timeConvert">
<xsl:with-param name="timeSec">
<xsl:value-of select="dive_duration"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
</xsl:if>
<xsl:if test="condition/visibility != '' and condition/visibility != 0">
<xsl:attribute name="visibility">
<xsl:value-of select="condition/visibility"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="condition/air_temp != ''">
<divetemperature>
<xsl:attribute name="air">
<xsl:value-of select="concat(format-number(condition/air_temp - 273.15, '0.0'), ' C')"/>
</xsl:attribute>
</divetemperature>
</xsl:if>
<xsl:if test="dive_site_ref/@ref != ''">
<location>
<xsl:variable name="ref">
<xsl:value-of select="dive_site_ref/@ref"/>
</xsl:variable>
<xsl:for-each select="//dive_site[@id=$ref]/geography/location|//dive_site[@id=$ref]/name">
<xsl:value-of select="."/>
<xsl:if test=". != '' and following-sibling::*[1]/* != ''"> / </xsl:if>
</xsl:for-each>
</location>
</xsl:if>
<xsl:if test="buddy_ref/@ref != ''">
<buddy>
<xsl:variable name="ref">
<xsl:value-of select="buddy_ref/@ref"/>
</xsl:variable>
<xsl:for-each select="//diver[@id=$ref]/personal/first_name|//diver[@id=$ref]/personal/nick_name|//diver[@id=$ref]/personal/family_name">
<xsl:value-of select="."/>
<xsl:if test=". != '' and (following-sibling::*[1] != '' or following-sibling::*[2] != '')"> / </xsl:if>
</xsl:for-each>
</buddy>
</xsl:if>
<xsl:if test="note/text != ''">
<notes>
<xsl:value-of select="note/text"/>
</notes>
</xsl:if>
<xsl:if test="equipment_used/weight_used &gt; 0">
<weightsystem description="unknown">
<xsl:attribute name="weight">
<xsl:value-of select="concat(format-number(equipment_used/weight_used, '0.0'), ' kg')"/>
</xsl:attribute>
</weightsystem>
</xsl:if>
<xsl:for-each select="lowesttemperature|informationafterdive/lowesttemperature|u:lowesttemperature|u:informationafterdive/u:lowesttemperature|u1:lowesttemperature|u1:informationafterdive/u1:lowesttemperature|condition/water_temp">
<temperature>
<xsl:if test="$temperatureSamples &gt; 0 or . != 273.15">
<xsl:attribute name="water">
<xsl:value-of select="concat(format-number(.- 273.15, '0.0'), ' C')"/>
</xsl:attribute>
</xsl:if>
</temperature>
</xsl:for-each>
<divecomputer deviceid="ffffffff">
<xsl:attribute name="model">
<xsl:value-of select="/uddf/generator/name|/u:uddf/u:generator/u:name|/u1:uddf/u1:generator/u1:name|/UDDF/history/modified/application/name"/>
</xsl:attribute>
</divecomputer>
<xsl:if test="equipment_used/tank_used != ''">
<xsl:for-each select="equipment_used/tank_used">
<cylinder>
<xsl:variable name="idx">
<xsl:value-of select="./tank_ref/@ref"/>
</xsl:variable>
<xsl:attribute name="size">
<xsl:value-of select="//equipment[@id=$idx]/tank/volume"/>
</xsl:attribute>
<xsl:attribute name="description">
<xsl:value-of select="//equipment[@id=$idx]/general/name"/>
</xsl:attribute>
<xsl:attribute name="start">
<xsl:value-of select="concat(substring-before(./pressure_start, '.') div 100000, ' bar')"/>
</xsl:attribute>
<xsl:attribute name="end">
<xsl:value-of select="concat(substring-before(./pressure_end, '.') div 100000, ' bar')"/>
</xsl:attribute>
</cylinder>
</xsl:for-each>
</xsl:if>
<xsl:apply-templates select="/uddf/gasdefinitions|/u:uddf/u:gasdefinitions|/u1:uddf/u1:gasdefinitions"/>
<depth>
<xsl:for-each select="greatestdepth|informationafterdive/greatestdepth|u:greatestdepth|u:informationafterdive/u:greatestdepth|u1:greatestdepth|u1:informationafterdive/u1:greatestdepth|max_depth">
<xsl:attribute name="max">
<xsl:value-of select="concat(format-number(., '0.00'), ' m')"/>
</xsl:attribute>
</xsl:for-each>
<xsl:for-each select="averagedepth|informationafterdive/averagedepth|u:averagedepth|u:informationafterdive/u:averagedepth|u1:averagedepth|u1:informationafterdive/u1:averagedepth">
<xsl:attribute name="mean">
<xsl:value-of select="concat(format-number(., '0.00'), ' m')"/>
</xsl:attribute>
</xsl:for-each>
</depth>
<!-- Aquadivelog gas switches require more lookups than other UDDF
formats I have seen -->
<xsl:for-each select="samples/switch">
<xsl:variable name="tank_idx">
<xsl:value-of select="./@tank"/>
</xsl:variable>
<xsl:variable name="idx">
<xsl:value-of select="//equipment_used/tank_used[@id=$tank_idx]/gas_ref/@ref"/>
</xsl:variable>
<event name="gaschange" type="11">
<xsl:attribute name="time">
<xsl:call-template name="timeConvert">
<xsl:with-param name="timeSec">
<xsl:value-of select="following-sibling::t"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:call-template name="gasConvert">
<xsl:with-param name="mix">
<xsl:value-of select="//gas_def/gas_mix[@id=$idx]/o2"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
</event>
</xsl:for-each>
<!-- Other gas switches than Aquadivelog -->
<xsl:for-each select="samples/waypoint/switchmix|u:samples/u:waypoint/u:switchmix|u1:samples/u1:waypoint/u1:switchmix">
<!-- Index to lookup gas per cent -->
<xsl:variable name="idx">
<xsl:value-of select="./@ref"/>
</xsl:variable>
<event name="gaschange" type="11">
<xsl:attribute name="time">
<xsl:call-template name="timeConvert">
<xsl:with-param name="timeSec">
<xsl:value-of select="preceding-sibling::divetime|preceding-sibling::u:divetime|preceding-sibling::u1:divetime"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:call-template name="gasConvert">
<xsl:with-param name="mix">
<xsl:value-of select="//gasdefinitions/mix[@id=$idx]/o2|//u:gasdefinitions/u:mix[@id=$idx]/u:o2|//u1:gasdefinitions/u1:mix[@id=$idx]/u1:o2"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
</event>
</xsl:for-each>
<xsl:for-each select="samples/waypoint|u:samples/u:waypoint|u1:samples/u1:waypoint|samples/d">
<sample>
<xsl:attribute name="time">
<xsl:call-template name="timeConvert">
<xsl:with-param name="timeSec">
<xsl:value-of select="divetime|u:divetime|u1:divetime|preceding-sibling::t[1]"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:choose>
<xsl:when test="depth != ''">
<xsl:attribute name="depth">
<xsl:value-of select="concat(format-number(depth, '0.00'), ' m')"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="u:depth|u1:depth != ''">
<xsl:attribute name="depth">
<xsl:value-of select="concat(format-number(u:depth|u1:depth, '0.00'), ' m')"/>
</xsl:attribute>
</xsl:when>
<xsl:when test=". != 0">
<xsl:attribute name="depth">
<xsl:value-of select="concat(format-number(., '0.00'), ' m')"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:if test="temperature != '' and $temperatureSamples &gt; 0">
<xsl:attribute name="temperature">
<xsl:value-of select="concat(format-number(temperature - 273.15, '0.0'), ' C')"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="u:temperature|u1:temperature != '' and $temperatureSamples &gt; 0">
<xsl:attribute name="temperature">
<xsl:value-of select="concat(format-number(u:temperature|u1:temperature - 273.15, '0.0'), ' C')"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="otu|u:otu|u1:otu &gt; 0">
<xsl:attribute name="otu">
<xsl:value-of select="otu|u:otu|u1:otu"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="cns|u:cns|u1:cns &gt; 0">
<xsl:attribute name="cns">
<xsl:value-of select="concat(cns|u:cns|u1:cns, ' C')"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="setpo2|u:setpo2|u1:setpo2 != ''">
<xsl:attribute name="po2">
<xsl:call-template name="convertPascal">
<xsl:with-param name="value">
<xsl:value-of select="setpo2|u:setpo2|u1:setpo2"/>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
</xsl:if>
</sample>
</xsl:for-each>
</dive>
</xsl:template>
<!-- convert time in seconds to minutes:seconds -->
<xsl:template name="timeConvert">
<xsl:param name="timeSec"/>
<xsl:if test="$timeSec != ''">
<xsl:value-of select="concat(floor(number($timeSec) div 60), ':', format-number(floor(number($timeSec) mod 60), '00'), ' min')"/>
</xsl:if>
</xsl:template>
<!-- end convert time -->
<!-- convert gas -->
<xsl:template name="gasConvert">
<xsl:param name="mix"/>
<xsl:if test="$mix != ''">
<xsl:choose>
<xsl:when test="$mix &gt;= 0">
<xsl:choose>
<xsl:when test="$mix &gt; 1">
<xsl:value-of select="concat($mix, '%')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($mix * 100, '%')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$mix"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<!-- end convert time -->
</xsl:stylesheet>