xsltjson icon indicating copy to clipboard operation
xsltjson copied to clipboard

XML2Json convert string to number

Open suhakopan opened this issue 5 years ago • 1 comments

Hi everyone,

I am using xml2json transform file.

My xml element:

<id>9999</id>

But after transform xml2json:

"id": 9999,

I want to this;

"id": "9999"

Because target source waiting to me this field string,but this file convert auto number my fields.

Please help

suhakopan avatar Jan 24 '20 07:01 suhakopan

There is a condition near the end of the file that determines what should be treated as a string. Just modify the line below.

<xsl:when test="normalize-space(.) ne . or not((string(.) castable as xs:integer and not(starts-with(string(.),'+')) and not(starts-with(string(.),'0') and not(. = '0'))) or (string(.) castable as xs:decimal and not(starts-with(string(.),'+')) and not(starts-with(.,'-.')) and not(starts-with(.,'.')) and not(starts-with(.,'-0') and not(starts-with(.,'-0.'))) and not(ends-with(.,'.')) and not(starts-with(.,'0') and not(starts-with(.,'0.'))) )) and not(. = 'false') and not(. = 'true') and not(. = 'null')">

ranania avatar Jan 27 '21 13:01 ranania