aboutsummaryrefslogtreecommitdiffstats
path: root/xslt
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2018-09-17 23:02:54 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-07 17:41:14 +0300
commitc44ece0ea1b42d36ed1b0813f9d377f36435ba13 (patch)
treee94f78997163747dac6302d5ce4bf2116b61a0ab /xslt
parent90b019bc8d5e7ce6ed0de2851312ef368cdc7a12 (diff)
downloadsubsurface-c44ece0ea1b42d36ed1b0813f9d377f36435ba13.tar.gz
CSV export: quote quotes
If a text field contains quotation mark ("), encode this with double quote (""). Fixes #1679 Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Diffstat (limited to 'xslt')
-rw-r--r--xslt/xml2manualcsv.xslt47
1 files changed, 42 insertions, 5 deletions
diff --git a/xslt/xml2manualcsv.xslt b/xslt/xml2manualcsv.xslt
index 1f0336171..d16cf8399 100644
--- a/xslt/xml2manualcsv.xslt
+++ b/xslt/xml2manualcsv.xslt
@@ -216,7 +216,10 @@
<xsl:value-of select="$fs"/>
<xsl:text>&quot;</xsl:text>
- <xsl:value-of select="@tags"/>
+ <xsl:call-template name="quote">
+ <xsl:with-param name="line" select="substring-before(translate(translate(@tags, $fs, ' '), $lf, ' '), '&quot;')"/>
+ <xsl:with-param name="remaining" select="substring-after(translate(translate(@tags, $fs, ' '), $lf, ' '), '&quot;')"/>
+ </xsl:call-template>
<xsl:text>&quot;</xsl:text>
<xsl:text>
@@ -330,25 +333,59 @@
<xsl:template match="divemaster">
<xsl:value-of select="$fs"/>
<xsl:text>&quot;</xsl:text>
- <xsl:value-of select="."/>
+ <xsl:call-template name="quote">
+ <xsl:with-param name="line" select="substring-before(translate(translate(., $fs, ' '), $lf, ' '), '&quot;')"/>
+ <xsl:with-param name="remaining" select="substring-after(translate(translate(., $fs, ' '), $lf, ' '), '&quot;')"/>
+ </xsl:call-template>
<xsl:text>&quot;</xsl:text>
</xsl:template>
<xsl:template match="buddy">
<xsl:value-of select="$fs"/>
<xsl:text>&quot;</xsl:text>
- <xsl:value-of select="."/>
+ <xsl:call-template name="quote">
+ <xsl:with-param name="line" select="substring-before(translate(translate(., $fs, ' '), $lf, ' '), '&quot;')"/>
+ <xsl:with-param name="remaining" select="substring-after(translate(translate(., $fs, ' '), $lf, ' '), '&quot;')"/>
+ </xsl:call-template>
<xsl:text>&quot;</xsl:text>
</xsl:template>
<xsl:template match="suit">
<xsl:value-of select="$fs"/>
<xsl:text>&quot;</xsl:text>
- <xsl:value-of select="."/>
+ <xsl:call-template name="quote">
+ <xsl:with-param name="line" select="substring-before(translate(translate(., $fs, ' '), $lf, ' '), '&quot;')"/>
+ <xsl:with-param name="remaining" select="substring-after(translate(translate(., $fs, ' '), $lf, ' '), '&quot;')"/>
+ </xsl:call-template>
<xsl:text>&quot;</xsl:text>
</xsl:template>
<xsl:template match="notes">
<xsl:value-of select="$fs"/>
<xsl:text>&quot;</xsl:text>
- <xsl:value-of select="translate(translate(., $fs, ' '), $lf, ' ')"/>
+ <xsl:call-template name="quote">
+ <xsl:with-param name="line" select="substring-before(translate(translate(., $fs, ' '), $lf, '\n'), '&quot;')"/>
+ <xsl:with-param name="remaining" select="substring-after(translate(translate(., $fs, ' '), $lf, '\n'), '&quot;')"/>
+ </xsl:call-template>
<xsl:text>&quot;</xsl:text>
</xsl:template>
+
+ <xsl:template name="quote">
+ <xsl:param name="line"/>
+ <xsl:param name="remaining"/>
+
+ <xsl:if test="$line != ''">
+ <xsl:value-of select="concat($line, '&quot;', '&quot;')"/>
+ </xsl:if>
+ <xsl:if test="$remaining != ''">
+ <xsl:choose>
+ <xsl:when test="substring-before($remaining, '&quot;') != ''">
+ <xsl:call-template name="quote">
+ <xsl:with-param name="line" select="substring-before($remaining, '&quot;')"/>
+ <xsl:with-param name="remaining" select="substring-after($remaining, '&quot;')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$remaining" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:if>
+ </xsl:template>
</xsl:stylesheet>