[PATCH] Convert deco info from JDiveLog to Subsurface

Miika Turkia miika.turkia at gmail.com
Sun Dec 16 12:24:30 PST 2012


Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
This should convert the deco information to Subsurface, but as I am not
familiar with deco diving, my testing was quite limited...
---
 xslt/jdivelog2subsurface.xslt |   94 ++++++++++++++++++++---------------------
 1 file changed, 46 insertions(+), 48 deletions(-)

diff --git a/xslt/jdivelog2subsurface.xslt b/xslt/jdivelog2subsurface.xslt
index d600c80..e480462 100644
--- a/xslt/jdivelog2subsurface.xslt
+++ b/xslt/jdivelog2subsurface.xslt
@@ -240,61 +240,59 @@ Comment: <xsl:value-of select="Comment"/>
       <!-- end gas change -->
 
       <!-- dive sample - all the depth and temp readings -->
-      <xsl:choose>
-        <xsl:when test="$delta != '0'">
-          <xsl:for-each select="DIVE/SAMPLES/D">
-            <xsl:variable name="timeSec" select="(position() - 1) * $delta"/>
-            <xsl:variable name="time" select="concat(floor($timeSec div 60), ':',
-              format-number(floor($timeSec mod 60), '00'), ' min')"/>
-            <xsl:choose>
-              <xsl:when test="name(following-sibling::*[1]) = 'TEMPERATURE'">
-                <sample time="{$time}" depth="{concat(., ' m')}">
-                  <xsl:attribute name="temp">
-                    <xsl:choose>
-                      <xsl:when test="$units = 'si'">
-                        <xsl:value-of select="concat(format-number(following-sibling::TEMPERATURE - 273.15, '00.0'), ' C')"/>
-                      </xsl:when>
-                      <xsl:otherwise>
-                        <xsl:value-of select="concat(following-sibling::TEMPERATURE, ' C')"/>
-                      </xsl:otherwise>
-                    </xsl:choose>
-                  </xsl:attribute>
-                </sample>
-              </xsl:when>
-              <xsl:otherwise>
-                <sample time="{$time}" depth="{concat(., ' m')}"/>
-              </xsl:otherwise>
-            </xsl:choose>
-          </xsl:for-each>
-        </xsl:when>
-        <xsl:otherwise>
-          <xsl:for-each select="DIVE/SAMPLES/D">
-            <sample>
+      <xsl:for-each select="DIVE/SAMPLES/D">
+        <sample>
+          <xsl:choose>
+            <xsl:when test="$delta != '0'">
+              <xsl:variable name="timeSec" select="(position() - 1) * $delta"/>
+              <xsl:attribute name="time">
+                <xsl:value-of select="concat(floor($timeSec div 60), ':',
+                  format-number(floor($timeSec mod 60), '00'), ' min')"/>
+              </xsl:attribute>
+            </xsl:when>
+            <xsl:otherwise>
               <xsl:attribute name="time">
                 <xsl:call-template name="timeConvert">
                   <xsl:with-param name="timeSec" select="preceding-sibling::T[1]"/>
                   <xsl:with-param name="units" select="$units"/>
                 </xsl:call-template>
               </xsl:attribute>
-              <xsl:if test="name(following-sibling::*[1]) = 'TEMPERATURE'">
-                <xsl:attribute name="temp">
-                  <xsl:choose>
-                    <xsl:when test="$units = 'si'">
-                      <xsl:value-of select="concat(format-number(following-sibling::TEMPERATURE - 273.15, '00.0'), ' C')"/>
-                    </xsl:when>
-                    <xsl:otherwise>
-                      <xsl:value-of select="concat(following-sibling::TEMPERATURE, ' C')"/>
-                    </xsl:otherwise>
-                  </xsl:choose>
+            </xsl:otherwise>
+          </xsl:choose>
+          <xsl:if test="name(following-sibling::*[1]) = 'TEMPERATURE'">
+            <xsl:attribute name="temp">
+              <xsl:choose>
+                <xsl:when test="$units = 'si'">
+                  <xsl:value-of select="concat(format-number(following-sibling::TEMPERATURE - 273.15, '00.0'), ' C')"/>
+                </xsl:when>
+                <xsl:otherwise>
+                  <xsl:value-of select="concat(following-sibling::TEMPERATURE, ' C')"/>
+                </xsl:otherwise>
+              </xsl:choose>
+            </xsl:attribute>
+          </xsl:if>
+          <xsl:attribute name="depth">
+            <xsl:value-of select="concat(., ' m')"/>
+          </xsl:attribute>
+          <xsl:if test="(name(following-sibling::*[1]) = 'DECOINFO') or (name(following-sibling::*[2]) = 'DECOINFO')">
+            <xsl:choose>
+              <xsl:when test="following-sibling::DECOINFO[1] = '0.0'">
+                <xsl:attribute name="ndl">
+                  <xsl:value-of select="concat(following-sibling::DECOINFO[1]/@tfs, ' min')"/>
                 </xsl:attribute>
-              </xsl:if>
-              <xsl:attribute name="depth">
-                <xsl:value-of select="concat(., ' m')"/>
-              </xsl:attribute>
-            </sample>
-          </xsl:for-each>
-        </xsl:otherwise>
-      </xsl:choose>
+              </xsl:when>
+              <xsl:otherwise>
+                <xsl:attribute name="stoptime">
+                  <xsl:value-of select="concat(following-sibling::DECOINFO[1]/@tfs, ' min')"/>
+                </xsl:attribute>
+                <xsl:attribute name="stopdepth">
+                  <xsl:value-of select="concat(following-sibling::DECOINFO[1], ' m')"/>
+                </xsl:attribute>
+              </xsl:otherwise>
+            </xsl:choose>
+          </xsl:if>
+        </sample>
+      </xsl:for-each>
       <!-- dive sample -->
 
     </dive>
-- 
1.7.9.5



More information about the subsurface mailing list