Is indent option on xml-to-json not supported?
Added by Martin Honnen about 4 years ago
Is it a known issue that xml-to-json($json-xml, map { 'indent' : true() })
doesn't indent the output?
I see that with Saxon-JS 2 both under Node.js as well as in the browser.
Samples:
<?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"
exclude-result-prefixes="#all">
<xsl:output method="text"/>
<xsl:template match="/" >
<xsl:value-of select="xml-to-json(., map { 'indent' : true() })"/>
</xsl:template>
</xsl:stylesheet>
XML straight from the XSLT 3 spec:
<?xml version="1.0" encoding="UTF-8"?>
<map xmlns="http://www.w3.org/2005/xpath-functions">
<string key='desc'>Distances between several cities, in kilometers.</string>
<string key='updated'>2014-02-04T18:50:45</string>
<boolean key="uptodate">true</boolean>
<null key="author"/>
<map key='cities'>
<array key="Brussels">
<map>
<string key="to">London</string>
<number key="distance">322</number>
</map>
<map>
<string key="to">Paris</string>
<number key="distance">265</number>
</map>
<map>
<string key="to">Amsterdam</string>
<number key="distance">173</number>
</map>
</array>
<array key="London">
<map>
<string key="to">Brussels</string>
<number key="distance">322</number>
</map>
<map>
<string key="to">Paris</string>
<number key="distance">344</number>
</map>
<map>
<string key="to">Amsterdam</string>
<number key="distance">358</number>
</map>
</array>
<array key="Paris">
<map>
<string key="to">Brussels</string>
<number key="distance">265</number>
</map>
<map>
<string key="to">London</string>
<number key="distance">344</number>
</map>
<map>
<string key="to">Amsterdam</string>
<number key="distance">431</number>
</map>
</array>
<array key="Amsterdam">
<map>
<string key="to">Brussels</string>
<number key="distance">173</number>
</map>
<map>
<string key="to">London</string>
<number key="distance">358</number>
</map>
<map>
<string key="to">Paris</string>
<number key="distance">431</number>
</map>
</array>
</map>
</map>
Result with Saxon Java is indented JSON but with Saxon-JS I get a single line
{"desc":"Distances between several cities, in kilometers.","updated":"2014-02-04T18:50:45","uptodate":true,"author":null,"cities":{"Brussels":[{"to":"London","distance":322},{"to":"Paris","distance":265},{"to":"Amsterdam","distance":173}],"London":[{"to":"Brussels","distance":322},{"to":"Paris","distance":344},{"to":"Amsterdam","distance":358}],"Paris":[{"to":"Brussels","distance":265},{"to":"London","distance":344},{"to":"Amsterdam","distance":431}],"Amsterdam":[{"to":"Brussels","distance":173},{"to":"London","distance":358},{"to":"Paris","distance":431}]}}
Replies (1)
RE: Is indent option on xml-to-json not supported? - Added by Michael Kay about 4 years ago
Looking at the code it seems there is no attempt to do any indentation.
This is of course not a conformance issue, because the effect of indent=true is to insert implementation-defined whitespace; but it's not very friendly, I agree.
Please register to reply