[PATCH 1/3] Support American date format on manual CSV import

Miika Turkia miika.turkia at gmail.com
Mon Nov 24 09:23:14 PST 2014


Assume that date is given in American format if it contains a slash (/)
character.

Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
 xslt/manualcsv2xml.xslt | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/xslt/manualcsv2xml.xslt b/xslt/manualcsv2xml.xslt
index 736b8b2..90691f4 100644
--- a/xslt/manualcsv2xml.xslt
+++ b/xslt/manualcsv2xml.xslt
@@ -74,10 +74,20 @@
       <xsl:attribute name="date">
         <xsl:choose>
           <xsl:when test="$dateField >= 0">
-            <xsl:call-template name="getFieldByIndex">
-              <xsl:with-param name="index" select="$dateField"/>
-              <xsl:with-param name="line" select="$line"/>
-            </xsl:call-template>
+            <xsl:variable name="tempdate">
+              <xsl:call-template name="getFieldByIndex">
+                <xsl:with-param name="index" select="$dateField"/>
+                <xsl:with-param name="line" select="$line"/>
+              </xsl:call-template>
+            </xsl:variable>
+            <xsl:choose>
+              <xsl:when test="substring-before($tempdate, '/') != ''">
+                <xsl:value-of select="concat(substring-after(substring-after($tempdate, '/'), '/'), '-', substring-before($tempdate, '/'), '-', substring-before(substring-after($tempdate, '/'), '/'))"/>
+              </xsl:when>
+              <xsl:otherwise>
+                <xsl:value-of select="$tempdate"/>
+              </xsl:otherwise>
+            </xsl:choose>
           </xsl:when>
           <xsl:otherwise>
             <xsl:value-of select="concat(substring($date, 1, 4), '-', substring($date, 5, 2), '-', substring($date, 7, 2))"/>
-- 
1.9.1



More information about the subsurface mailing list