diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2017-07-09 12:31:58 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-15 14:44:07 +0900 |
commit | 0135597265cbd63211bd5d2c222a5c4d58e4c0d4 (patch) | |
tree | 8ec9d35b867836c2d9c68a2d4e4cbee705f66a7c | |
parent | 9b7d321c8786bae7e1d4d8673ba541d7884c558b (diff) | |
download | subsurface-0135597265cbd63211bd5d2c222a5c4d58e4c0d4.tar.gz |
CSV export: show units on header
Let's show the units in CSV header so the actual fields have only the
values. This should be easier to parse with some other programs.
Fixes #472
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
-rw-r--r-- | xslt/xml2manualcsv.xslt | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/xslt/xml2manualcsv.xslt b/xslt/xml2manualcsv.xslt index fcb97b52d..e240d3123 100644 --- a/xslt/xml2manualcsv.xslt +++ b/xslt/xml2manualcsv.xslt @@ -11,7 +11,14 @@ </xsl:text></xsl:variable> <xsl:template match="/divelog/dives"> - <xsl:value-of select="concat('"dive number"', $fs, '"date"', $fs, '"time"', $fs, '"duration"', $fs, '"maxdepth"', $fs, '"avgdepth"', $fs, '"airtemp"', $fs, '"watertemp"', $fs, '"cylinder size"', $fs, '"startpressure"', $fs, '"endpressure"', $fs, '"o2"', $fs, '"he"', $fs, '"location"', $fs, '"gps"', $fs, '"divemaster"', $fs, '"buddy"', $fs, '"suit"', $fs, '"rating"', $fs, '"visibility"', $fs, '"notes"', $fs, '"weight"', $fs, '"tags"')"/> + <xsl:choose> + <xsl:when test="$units = 1"> + <xsl:value-of select="concat('"dive number"', $fs, '"date"', $fs, '"time"', $fs, '"duration"', $fs, '"maxdepth (ft)"', $fs, '"avgdepth (ft)"', $fs, '"airtemp (F)"', $fs, '"watertemp (F)"', $fs, '"cylinder size (cuft)"', $fs, '"startpressure (psi)"', $fs, '"endpressure (psi)"', $fs, '"o2"', $fs, '"he"', $fs, '"location"', $fs, '"gps"', $fs, '"divemaster"', $fs, '"buddy"', $fs, '"suit"', $fs, '"rating"', $fs, '"visibility"', $fs, '"notes"', $fs, '"weight (lbs)"', $fs, '"tags"')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="concat('"dive number"', $fs, '"date"', $fs, '"time"', $fs, '"duration"', $fs, '"maxdepth (m)"', $fs, '"avgdepth (m)"', $fs, '"airtemp (C)"', $fs, '"watertemp (C)"', $fs, '"cylinder size (l)"', $fs, '"startpressure (bar)"', $fs, '"endpressure (bar)"', $fs, '"o2"', $fs, '"he"', $fs, '"location"', $fs, '"gps"', $fs, '"divemaster"', $fs, '"buddy"', $fs, '"suit"', $fs, '"rating"', $fs, '"visibility"', $fs, '"notes"', $fs, '"weight (kg)"', $fs, '"tags"')"/> + </xsl:otherwise> + </xsl:choose> <xsl:text> </xsl:text> <xsl:apply-templates select="dive|trip/dive"/> @@ -71,10 +78,10 @@ <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((cylinder[1]/@size div 14.7 * 3000) * 0.035315, '#.#'), ' cuft')"/> + <xsl:value-of select="concat(format-number((substring-before(cylinder[1]/@size, ' ') div 14.7 * 3000) * 0.035315, '#.#'), '')"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="cylinder[1]/@size"/> + <xsl:value-of select="substring-before(cylinder[1]/@size, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -82,10 +89,17 @@ <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((substring-before(divecomputer[1]/sample[@pressure]/@pressure, ' ') * 14.5037738007), '#'), ' psi')"/> + <xsl:choose> + <xsl:when test="divecomputer[1]/sample[@pressure]/@pressure > 0"> + <xsl:value-of select="concat(format-number((substring-before(divecomputer[1]/sample[@pressure]/@pressure, ' ') * 14.5037738007), '#'), '')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="''"/> + </xsl:otherwise> + </xsl:choose> </xsl:when> <xsl:otherwise> - <xsl:value-of select="divecomputer[1]/sample[@pressure]/@pressure"/> + <xsl:value-of select="substring-before(divecomputer[1]/sample[@pressure]/@pressure, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -93,10 +107,17 @@ <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((substring-before(divecomputer[1]/sample[@pressure][last()]/@pressure, ' ') * 14.5037738007), '#'), ' psi')"/> + <xsl:choose> + <xsl:when test="divecomputer[1]/sample[@pressure][last()]/@pressure > 0"> + <xsl:value-of select="concat(format-number((substring-before(divecomputer[1]/sample[@pressure][last()]/@pressure, ' ') * 14.5037738007), '#'), '')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="''"/> + </xsl:otherwise> + </xsl:choose> </xsl:when> <xsl:otherwise> - <xsl:value-of select="divecomputer[1]/sample[@pressure][last()]/@pressure"/> + <xsl:value-of select="substring-before(divecomputer[1]/sample[@pressure][last()]/@pressure, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -184,10 +205,10 @@ <xsl:if test="weightsystem"> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((sum(xt:node-set($trimmedweightlist)/node()) div 0.453592), '#.##'), ' lb')"/> + <xsl:value-of select="concat(format-number((sum(xt:node-set($trimmedweightlist)/node()) div 0.453592), '#.##'), '')"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="concat(sum(xt:node-set($trimmedweightlist)/node()), ' kg')"/> + <xsl:value-of select="concat(sum(xt:node-set($trimmedweightlist)/node()), '')"/> </xsl:otherwise> </xsl:choose> </xsl:if> @@ -206,10 +227,10 @@ <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((substring-before(@max, ' ') div 0.3048), '#.##'), ' ft')"/> + <xsl:value-of select="concat(format-number((substring-before(@max, ' ') div 0.3048), '#.##'), '')"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="@max"/> + <xsl:value-of select="substring-before(@max, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -217,10 +238,10 @@ <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((substring-before(@mean, ' ') div 0.3048), '#.##'), ' ft')"/> + <xsl:value-of select="concat(format-number((substring-before(@mean, ' ') div 0.3048), '#.##'), '')"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="@mean"/> + <xsl:value-of select="substring-before(@mean, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -231,11 +252,11 @@ <xsl:choose> <xsl:when test="$units = 1"> <xsl:if test="substring-before(@air, ' ') > 0"> - <xsl:value-of select="concat(format-number((substring-before(@air, ' ') * 1.8) + 32, '0.0'), ' F')"/> + <xsl:value-of select="concat(format-number((substring-before(@air, ' ') * 1.8) + 32, '0.0'), '')"/> </xsl:if> </xsl:when> <xsl:otherwise> - <xsl:value-of select="@air"/> + <xsl:value-of select="substring-before(@air, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -244,11 +265,11 @@ <xsl:choose> <xsl:when test="$units = 1"> <xsl:if test="substring-before(@water, ' ') > 0"> - <xsl:value-of select="concat(format-number((substring-before(@water, ' ') * 1.8) + 32, '0.0'), ' F')"/> + <xsl:value-of select="concat(format-number((substring-before(@water, ' ') * 1.8) + 32, '0.0'), '')"/> </xsl:if> </xsl:when> <xsl:otherwise> - <xsl:value-of select="@water"/> + <xsl:value-of select="substring-before(@water, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -258,10 +279,10 @@ <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((substring-before(@size, ' ') div 14.7 * 3000) * 0.035315, '#.#'), ' cuft')"/> + <xsl:value-of select="concat(format-number((substring-before(@size, ' ') div 14.7 * 3000) * 0.035315, '#.#'), '')"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="@size"/> + <xsl:value-of select="substring-before(@size, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -269,10 +290,10 @@ <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((substring-before(@start, ' ') * 14.5037738007), '#'), ' psi')"/> + <xsl:value-of select="concat(format-number((substring-before(@start, ' ') * 14.5037738007), '#'), '')"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="@start"/> + <xsl:value-of select="substring-before(@start, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> @@ -280,10 +301,10 @@ <xsl:text>"</xsl:text> <xsl:choose> <xsl:when test="$units = 1"> - <xsl:value-of select="concat(format-number((substring-before(@end, ' ') * 14.5037738007), '#'), ' psi')"/> + <xsl:value-of select="concat(format-number((substring-before(@end, ' ') * 14.5037738007), '#'), '')"/> </xsl:when> <xsl:otherwise> - <xsl:value-of select="@end"/> + <xsl:value-of select="substring-before(@end, ' ')"/> </xsl:otherwise> </xsl:choose> <xsl:text>"</xsl:text> |