diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2013-02-27 20:36:34 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-02-27 10:39:03 -0800 |
commit | 438299ff55fb9b62290d008d81a6e6d7e9c2e06b (patch) | |
tree | 2f8e5a0e0e8d576fe6cf48219b4632d2e57e793a /xslt | |
parent | d2f9ee8d45ef9c87f0981f7b786a757f631b792b (diff) | |
download | subsurface-438299ff55fb9b62290d008d81a6e6d7e9c2e06b.tar.gz |
Parse ISO 8601 time format
This is an XSLT implementation of a function to parse the ISO 8601
datetime format used in uddf.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'xslt')
-rw-r--r-- | xslt/commonTemplates.xsl | 61 | ||||
-rw-r--r-- | xslt/uddf.xslt | 12 |
2 files changed, 67 insertions, 6 deletions
diff --git a/xslt/commonTemplates.xsl b/xslt/commonTemplates.xsl new file mode 100644 index 000000000..2d64a05d8 --- /dev/null +++ b/xslt/commonTemplates.xsl @@ -0,0 +1,61 @@ +<?xml version="1.0"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + + <xsl:template name="datetime"> + <xsl:param name="value"/> + + <xsl:variable name="date"> + <xsl:choose> + <xsl:when test="contains($value, 'T')"> + <xsl:value-of select="substring-before($value, 'T')"/> + </xsl:when> + <xsl:when test="contains($value, ' ')"> + <xsl:value-of select="substring-before($value, ' ')"/> + </xsl:when> + </xsl:choose> + </xsl:variable> + + <xsl:variable name="time"> + <xsl:choose> + <xsl:when test="contains($value, 'T')"> + <xsl:value-of select="substring-after($value, 'T')"/> + </xsl:when> + <xsl:when test="contains($value, ' ')"> + <xsl:value-of select="substring-after($value, ' ')"/> + </xsl:when> + </xsl:choose> + </xsl:variable> + + <xsl:if test="$date != ''"> + <xsl:attribute name="date"> + <xsl:choose> + <xsl:when test="contains($date, '-')"> + <xsl:value-of select="$date"/> + </xsl:when> + <xsl:otherwise> + <xsl:variable name="year" select="substring($date, 1, 4)"/> + <xsl:variable name="month" select="substring($date, 5, 2)"/> + <xsl:variable name="day" select="substring($date, 7,2)"/> + <xsl:value-of select="concat($year,'-',$month,'-',$day)"/> + </xsl:otherwise> + </xsl:choose> + </xsl:attribute> + </xsl:if> + <xsl:if test="$time != ''"> + <xsl:attribute name="time"> + <xsl:choose> + <xsl:when test="contains($time, ':')"> + <xsl:value-of select="$time"/> + </xsl:when> + <xsl:otherwise> + <xsl:variable name="hour" select="substring($time, 1, 2)"/> + <xsl:variable name="minute" select="substring($time, 3, 2)"/> + <xsl:variable name="second" select="substring($time, 5,2)"/> + <xsl:value-of select="concat($hour,':',$minute,':',$second)"/> + </xsl:otherwise> + </xsl:choose> + </xsl:attribute> + </xsl:if> + </xsl:template> + +</xsl:stylesheet> diff --git a/xslt/uddf.xslt b/xslt/uddf.xslt index d9b3f9a7d..1b45ccad6 100644 --- a/xslt/uddf.xslt +++ b/xslt/uddf.xslt @@ -3,6 +3,7 @@ xmlns:u="http://www.streit.cc/uddf/3.2/" exclude-result-prefixes="u" version="1.0"> + <xsl:import href="commonTemplates.xsl"/> <xsl:strip-space elements="*"/> <xsl:output method="xml" indent="yes"/> @@ -61,12 +62,11 @@ </xsl:attribute> </xsl:when> <xsl:when test="informationbeforedive/datetime|u:informationbeforedive/u:datetime != ''"> - <xsl:attribute name="date"> - <xsl:value-of select="substring-before(informationbeforedive/datetime|u:informationbeforedive/u:datetime, 'T')"/> - </xsl:attribute> - <xsl:attribute name="time"> - <xsl:value-of select="substring-after(informationbeforedive/datetime|u:informationbeforedive/u:datetime, 'T')"/> - </xsl:attribute> + <xsl:call-template name="datetime"> + <xsl:with-param name="value"> + <xsl:value-of select="informationbeforedive/datetime|u:informationbeforedive/u:datetime"/> + </xsl:with-param> + </xsl:call-template> </xsl:when> </xsl:choose> |