From 1e45637575d316e86360a6bde7729f396bd2175b Mon Sep 17 00:00:00 2001
From: Miika Turkia <miika.turkia@gmail.com>
Date: Tue, 13 Feb 2018 22:40:01 +0200
Subject: [PATCH] UDCF import: support for imperial depths

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
---
 xslt/udcf.xslt | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/xslt/udcf.xslt b/xslt/udcf.xslt
index 623273b8d..f95e2036b 100644
--- a/xslt/udcf.xslt
+++ b/xslt/udcf.xslt
@@ -1,6 +1,7 @@
 <?xml version="1.0"?>
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:strip-space elements="*"/>
+  <xsl:include href="commonTemplates.xsl"/>
   <xsl:output method="xml" indent="yes"/>
 
   <xsl:template match="/">
@@ -125,7 +126,24 @@
 		  format-number(floor($timeSec mod $timeconvert), '00'), ' min')"/>
 	      </xsl:attribute>
 	      <xsl:attribute name="depth">
-		<xsl:value-of select="concat(., ' m')"/>
+                <xsl:choose>
+                  <xsl:when test="//units|//UNITS = 'imperial'">
+                    <xsl:call-template name="depthConvert">
+                      <xsl:with-param name="depth">
+                        <xsl:value-of select="."/>
+                      </xsl:with-param>
+                      <xsl:with-param name="units" select="'Imperial'"/>
+                    </xsl:call-template>
+                  </xsl:when>
+                  <xsl:otherwise>
+                    <xsl:call-template name="depthConvert">
+                      <xsl:with-param name="depth">
+                        <xsl:value-of select="."/>
+                      </xsl:with-param>
+                      <xsl:with-param name="units" select="'Metric'"/>
+                    </xsl:call-template>
+                  </xsl:otherwise>
+                </xsl:choose>
 	      </xsl:attribute>
 	    </sample>
 	  </xsl:for-each>
@@ -161,7 +179,24 @@
 		  format-number(floor($timeSec mod 60), '00'), ' min')"/>
 	      </xsl:attribute>
 	      <xsl:attribute name="depth">
-		<xsl:value-of select="concat(., ' m')"/>
+                <xsl:choose>
+                  <xsl:when test="//units|//UNITS = 'imperial'">
+                    <xsl:call-template name="depthConvert">
+                      <xsl:with-param name="depth">
+                        <xsl:value-of select="."/>
+                      </xsl:with-param>
+                      <xsl:with-param name="units" select="'Imperial'"/>
+                    </xsl:call-template>
+                  </xsl:when>
+                  <xsl:otherwise>
+                    <xsl:call-template name="depthConvert">
+                      <xsl:with-param name="depth">
+                        <xsl:value-of select="."/>
+                      </xsl:with-param>
+                      <xsl:with-param name="units" select="'Metric'"/>
+                    </xsl:call-template>
+                  </xsl:otherwise>
+                </xsl:choose>
 	      </xsl:attribute>
 	    </sample>
 	  </xsl:for-each>