As we join LOCATION with SITE on divelogs.de import using slash (/) as a
separator, we might as well split on last slash on export.

Signed-off-by: Miika Turkia <[email protected]>
---
 xslt/divelogs-export.xslt | 47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/xslt/divelogs-export.xslt b/xslt/divelogs-export.xslt
index abfcc89..b23ee48 100644
--- a/xslt/divelogs-export.xslt
+++ b/xslt/divelogs-export.xslt
@@ -34,12 +34,34 @@
     <DIVETIMESEC>
       <xsl:value-of select="$duration"/>
     </DIVETIMESEC>
-      <xsl:variable name="uuid">
-        <xsl:value-of select="@divesiteid"/>
-      </xsl:variable>
-    <LOCATION>
+
+    <xsl:variable name="uuid">
+      <xsl:value-of select="@divesiteid"/>
+    </xsl:variable>
+    <xsl:variable name="location">
       <xsl:value-of select="//site[@uuid = $uuid]/@name"/>
-    </LOCATION>
+    </xsl:variable>
+    <xsl:choose>
+      <xsl:when test="contains($location, '/')">
+        <xsl:variable name="site">
+          <xsl:call-template name="basename">
+            <xsl:with-param name="value" select="$location"/>
+          </xsl:call-template>
+        </xsl:variable>
+        <SITE>
+          <xsl:value-of select="$site"/>
+        </SITE>
+        <LOCATION>
+          <xsl:value-of select="substring($location, 0, 
string-length($location) - string-length($site))"/>
+        </LOCATION>
+      </xsl:when>
+      <xsl:otherwise>
+        <SITE>
+          <xsl:value-of select="$location"/>
+        </SITE>
+      </xsl:otherwise>
+    </xsl:choose>
+
     <WATERVIZIBILITY>
       <xsl:value-of select="@visibility"/>
     </WATERVIZIBILITY>
@@ -412,4 +434,19 @@
 
   </xsl:template>
 
+  <xsl:template name="basename">
+    <xsl:param name="value" />
+
+    <xsl:choose>
+      <xsl:when test="contains($value, '/')">
+        <xsl:call-template name="basename">
+          <xsl:with-param name="value" select="substring-after($value, '/')" />
+        </xsl:call-template>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="$value" />
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
 </xsl:stylesheet>
-- 
2.1.4

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to