Skip to content

Commit

Permalink
Essential part of upstream pull req No. 20
Browse files Browse the repository at this point in the history
doekman/xml2json-xslt#20

 Some numeric values would not get formatted to valid JSON. This
 incorporates the suggestions from issue #15.

Also fixed whitespace of original patch.
Additional fix for related issue will follow.
  • Loading branch information
dm8tbr committed May 25, 2015
1 parent 3d2ab9a commit 0b1ac3e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions web/xml2json.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,22 @@

<!-- number (no support for javascript mantissa) -->
<xsl:template match="text()[not(string(number())='NaN' or
(starts-with(.,'0' ) and . != '0'))]">
<xsl:value-of select="."/>
(starts-with(.,'0' ) and . != '0' and not(starts-with(.,'0.' ))) or
(starts-with(.,'-0' ) and . != '-0' and not(starts-with(.,'-0.' ))))]">
<xsl:choose>
<xsl:when test="starts-with(.,'.')">
<xsl:value-of select="concat('0',.)"/>
</xsl:when>
<xsl:when test="starts-with(.,'-.')">
<xsl:value-of select="concat('-0.', substring(.,3))"/>
</xsl:when>
<xsl:when test="substring(., string-length(.))='.'">
<xsl:value-of select="concat(.,0)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- boolean, case-insensitive -->
Expand Down

0 comments on commit 0b1ac3e

Please sign in to comment.