Details
Description
This is a bug report on the XSLT 3.0 development branch of Xalan Java.
I have tested the newly introduced parse-json function on all sorts of allowed input and it appears the implementation in Xalan fails to recognize a simple JSON string, number, boolean and the null value.
Test case is:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:map="http://www.w3.org/2005/xpath-functions/map" xmlns:array="http://www.w3.org/2005/xpath-functions/array" exclude-result-prefixes="xs map array"> <xsl:output method="xml" indent="yes"/> <xsl:template match="array"> <array-test> <xsl:variable name="xdm-array" select="parse-json(.)"/> <array-instance-of-test> <xsl:value-of select="$xdm-array instance of array(*)"/> </array-instance-of-test> </array-test> </xsl:template> <xsl:template match="map"> <map-test> <xsl:variable name="xdm-map" select="parse-json(.)"/> <map-instance-of-test> <xsl:value-of select="$xdm-map instance of map(*)"/> </map-instance-of-test> </map-test> </xsl:template> <xsl:template match="string"> <string-test> <xsl:variable name="str" select="parse-json(.)"/> <string-instance-of-test> <xsl:value-of select="$str instance of xs:string"/> </string-instance-of-test> </string-test> </xsl:template> <xsl:template match="number"> <number-test> <xsl:variable name="dbl" select="parse-json(.)"/> <number-instance-of-test> <xsl:value-of select="$dbl instance of xs:double"/> </number-instance-of-test> </number-test> </xsl:template> <xsl:template match="boolean"> <boolean-test> <xsl:variable name="bool" select="parse-json(.)"/> <boolean-instance-of-test> <xsl:value-of select="$bool instance of xs:boolean"/> </boolean-instance-of-test> </boolean-test> </xsl:template> <xsl:template match="empty"> <empty-seq-test> <xsl:variable name="empty-seq" select="parse-json(.)"/> <empty-seq-instance-of-test> <xsl:value-of select="$empty-seq instance of item()? and empty($empty-seq)"/> </empty-seq-instance-of-test> </empty-seq-test> </xsl:template> <xsl:template match="/"> <xsl:copy> <xsl:apply-templates/> <xsl:comment>Run with <xsl:value-of select="system-property('xsl:vendor')"/> at <xsl:value-of select="current-dateTime()"/></xsl:comment> </xsl:copy> </xsl:template> </xsl:stylesheet>
Run against input sample with sample data
<root> <map>{ "name" : "foo", "data" : [3,2,1] }</map> <array>[ { "name" : "foo", "value" : 3.2 } ]</array> <string>"foo"</string> <number>42</number> <boolean>false</boolean> <empty>null</empty> </root>
this with Xalan gives an error
<?xml version="1.0" encoding="UTF-8"?> <map-test> <map-instance-of-test>true</map-instance-of-test> </map-test> <array-test> <array-instance-of-test>true</array-instance-of-test> </array-test> file:///C:/Users/marti/IdeaProjects/xalan-java/../../OneDrive/Documents/xslt/blog-xslt-3-by-example/xalan-xslt3-tests/parse-json-test2.xsl; Zeilennummer31; Spaltennummer56; FOUT1190 : The 1st argument provided with function call fn:parse-json is not a correct json lexical string. A json string can begin only with '{' or '[' characters.
while Saxon HE 12 Java happily parses all values and outputs e.g.
<?xml version="1.0" encoding="UTF-8"?> <map-test> <map-instance-of-test>true</map-instance-of-test> </map-test> <array-test> <array-instance-of-test>true</array-instance-of-test> </array-test> <string-test> <string-instance-of-test>true</string-instance-of-test> </string-test> <number-test> <number-instance-of-test>true</number-instance-of-test> </number-test> <boolean-test> <boolean-instance-of-test>true</boolean-instance-of-test> </boolean-test> <empty-seq-test> <empty-seq-instance-of-test>true</empty-seq-instance-of-test> </empty-seq-test>