diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2016-05-02 20:11:35 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-05-02 10:25:03 -0700 |
commit | a83c674139562010e9b9ee281b121ed4434c8a5a (patch) | |
tree | 32bc4a0fc779a2f9ccb10e972cc08acadc3e29e9 /xslt/csv2xml.xslt | |
parent | 43f911242032982a2456ef8f7fc0d8a3a1d3dd6b (diff) | |
download | subsurface-a83c674139562010e9b9ee281b121ed4434c8a5a.tar.gz |
CSV import: support for user specified date format
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'xslt/csv2xml.xslt')
-rw-r--r-- | xslt/csv2xml.xslt | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/xslt/csv2xml.xslt b/xslt/csv2xml.xslt index 7dc4fa4be..5c97b7aee 100644 --- a/xslt/csv2xml.xslt +++ b/xslt/csv2xml.xslt @@ -3,6 +3,7 @@ <xsl:include href="commonTemplates.xsl"/> <xsl:strip-space elements="*"/> <xsl:param name="dateField" select="dateField"/> + <xsl:param name="datefmt" select="datefmt"/> <xsl:param name="timeField" select="timeField"/> <xsl:param name="depthField" select="depthField"/> <xsl:param name="tempField" select="tempField"/> @@ -43,10 +44,42 @@ <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="substring-after(substring-after(., $lf), $lf)"/> - </xsl:call-template> + <xsl:variable name="indate"> + <xsl:call-template name="getFieldByIndex"> + <xsl:with-param name="index" select="$dateField"/> + <xsl:with-param name="line" select="substring-after(substring-after(., $lf), $lf)"/> + </xsl:call-template> + </xsl:variable> + <xsl:variable name="separator"> + <xsl:choose> + <xsl:when test="substring-before($indate, '.') != ''"> + <xsl:value-of select="'.'"/> + </xsl:when> + <xsl:when test="substring-before($indate, '-') != ''"> + <xsl:value-of select="'-'"/> + </xsl:when> + <xsl:when test="substring-before($indate, '/') != ''"> + <xsl:value-of select="'/'"/> + </xsl:when> + </xsl:choose> + </xsl:variable> + <xsl:choose> + <!-- dd.mm.yyyy --> + <xsl:when test="$datefmt = 0"> + <xsl:value-of select="translate(concat(substring-after(substring-after($indate, $separator), $separator), '-', substring-before(substring-after($indate, $separator), $separator), '-', substring-before($indate, $separator)), ' ', '')"/> + </xsl:when> + <!-- mm.yy.yyyy --> + <xsl:when test="$datefmt = 1"> + <xsl:value-of select="translate(concat(substring-after(substring-after($indate, $separator), $separator), '-', substring-before($indate, $separator), '-', substring-before(substring-after($indate, $separator), $separator)), ' ', '')"/> + </xsl:when> + <!-- yyyy.mm.dd --> + <xsl:when test="$datefmt = 2"> + <xsl:value-of select="translate(concat(substring-before($indate, $separator), '-', substring-before(substring-after($indate, $separator), $separator), '-', substring-after(substring-after($indate, $separator), $separator)), ' ', '')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="'1900-1-1'"/> + </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))"/> |