11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<xsl : stylesheet version =" 1.0" xmlns : xsl =" http://www.w3.org/1999/XSL/Transform" >
33<!--
4- Copyright (c) 2006, Doeke Zanstra
4+ Copyright (c) 2006,2008 Doeke Zanstra
55 All rights reserved.
66
7- Note: This is a hacked version of xml2json.xslt
8- **** All numbers will be output as strings to prevent version numbers like
9- **** 1.0 changing to 1
10- **** If you want the original version, get it from
11- **** http://code.google.com/p/xml2json-xslt/
12-
137 Redistribution and use in source and binary forms, with or without modification,
148 are permitted provided that the following conditions are met:
159
1913 following disclaimer in the documentation and/or other materials provided with
2014 the distribution.
2115
22- Neither the name of the dzLib nor the names of its contributors may be used to
23- endorse or promote products derived from this software without specific prior
24- written permission.
25-
2616 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2717 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2818 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
3626-->
3727
3828 <xsl : output indent =" no" omit-xml-declaration =" yes" method =" text" encoding =" UTF-8" media-type =" text/x-json" />
39- <xsl : strip-space elements =" *" />
29+ <xsl : strip-space elements =" *" />
4030 <!-- contant-->
4131 <xsl : variable name =" d" >0123456789</xsl : variable >
4232
130120 </xsl : choose >
131121 </xsl : template >
132122
133- <!-- number (no support for javascript mantise) -->
134- <xsl : template match =" text()[not(string(number())='NaN')]" >
123+ <!-- number (no support for javascript mantissa) -->
124+ <xsl : template match =" text()[not(string(number())='NaN' or
125+ (starts-with(.,'0' ) and . != '0'))]" >
135126 " <xsl : value-of select =" ." />"
136127 </xsl : template >
137128
138129 <!-- boolean, case-insensitive -->
139130 <xsl : template match =" text()[translate(.,'TRUE','true')='true']" >true</xsl : template >
140131 <xsl : template match =" text()[translate(.,'FALSE','false')='false']" >false</xsl : template >
141132
142- <!-- item:null -->
143- <xsl : template match =" *[count(child::node())=0]" >
144- <xsl : call-template name =" escape-string" >
145- <xsl : with-param name =" s" select =" local-name()" />
146- </xsl : call-template >
147- <xsl : text >:null</xsl : text >
148- <xsl : if test =" following-sibling::*" >,</xsl : if >
149- </xsl : template >
150-
151133 <!-- object -->
152134 <xsl : template match =" *" name =" base" >
153135 <xsl : if test =" not(preceding-sibling::*)" >{</xsl : if >
154136 <xsl : call-template name =" escape-string" >
155137 <xsl : with-param name =" s" select =" name()" />
156138 </xsl : call-template >
157139 <xsl : text >:</xsl : text >
158- <xsl : apply-templates select =" child::node()" />
140+ <!-- check type of node -->
141+ <xsl : choose >
142+ <!-- null nodes -->
143+ <xsl : when test =" count(child::node())=0" >null</xsl : when >
144+ <!-- other nodes -->
145+ <xsl : otherwise >
146+ <xsl : apply-templates select =" child::node()" />
147+ </xsl : otherwise >
148+ </xsl : choose >
149+ <!-- end of type check -->
159150 <xsl : if test =" following-sibling::*" >,</xsl : if >
160151 <xsl : if test =" not(following-sibling::*)" >}</xsl : if >
161152 </xsl : template >
180171 <xsl : apply-templates select =" node()" />
181172 </xsl : template >
182173
183- </xsl : stylesheet >
174+ </xsl : stylesheet >
0 commit comments