Martin Honnen created XALANJ-2754:
-------------------------------------
Summary: parse-json handles only JSON maps and objects but not the
primitive values string, number, boolean nor the null value
Key: XALANJ-2754
URL: https://issues.apache.org/jira/browse/XALANJ-2754
Project: XalanJ2
Issue Type: Bug
Security Level: No security risk; visible to anyone (Ordinary problems in
Xalan projects. Anybody can view the issue.)
Components: Xalan, XPath
Affects Versions: The Latest Development Code
Reporter: Martin Honnen
Attachments: parse-json-test-data.xml, parse-json-test2.xsl
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:
{code:java}
<?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>
{code}
Run against input sample with sample data
{code:java}
<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>{code}
this with Xalan gives an error
{noformat}
<?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.{noformat}
while Saxon HE 12 Java happily parses all values and outputs e.g.
{code:java}
<?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>{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]