kopia lustrzana https://github.com/conorpp/u2f-zero
Fix BOM xsl to quote strings containing commas
rodzic
4fcc9bee0e
commit
8d66cc663b
|
@ -84,8 +84,28 @@
|
|||
|
||||
<!-- only if this field entry exists in this fields section -->
|
||||
<xsl:if test="@name=$allnames">
|
||||
<!-- content of the field -->
|
||||
<xsl:value-of select="."/>
|
||||
|
||||
<!-- 1. quote any fields that contain commas -->
|
||||
<!-- 2. quotes inside quotes need to be escaped using quotes (RFC 4180) -->
|
||||
<xsl:choose>
|
||||
<xsl:when test="text()[contains(., ',')]">
|
||||
<!-- content of the field (in quotes), with quotes quote-escaped -->
|
||||
<xsl:variable name="quot">"</xsl:variable>
|
||||
<xsl:variable name="newtext">
|
||||
<xsl:call-template name="replace">
|
||||
<xsl:with-param name="haystack" select="." />
|
||||
<xsl:with-param name="needle" select="$quot" />
|
||||
<xsl:with-param name="replacement" select="concat($quot, $quot)" />
|
||||
</xsl:call-template>
|
||||
</xsl:variable>
|
||||
<xsl:value-of select="concat($quot, $newtext, $quot)" />
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<!-- content of the field -->
|
||||
<xsl:value-of select="."/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
||||
</xsl:if>
|
||||
<!--
|
||||
If it does not exist, use an empty cell in output for this row.
|
||||
|
@ -95,4 +115,29 @@
|
|||
</xsl:for-each>
|
||||
</xsl:template>
|
||||
|
||||
<!-- replace() not in XSLT v1.0 -->
|
||||
<xsl:template name="replace">
|
||||
<xsl:param name="haystack" />
|
||||
<xsl:param name="needle" />
|
||||
<xsl:param name="replacement" />
|
||||
<xsl:choose>
|
||||
<xsl:when test="$haystack = '' or $needle = '' or not($needle)" >
|
||||
<!-- Bail out -->
|
||||
<xsl:value-of select="$haystack" />
|
||||
</xsl:when>
|
||||
<xsl:when test="contains($haystack, $needle)">
|
||||
<xsl:value-of select="substring-before($haystack, $needle)" />
|
||||
<xsl:value-of select="$replacement" />
|
||||
<xsl:call-template name="replace">
|
||||
<xsl:with-param name="haystack" select="substring-after($haystack, $needle)" />
|
||||
<xsl:with-param name="needle" select="$needle" />
|
||||
<xsl:with-param name="replacement" select="$replacement" />
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$haystack" />
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
|
Ładowanie…
Reference in New Issue