xsl-list
[Top] [All Lists]

Re: [xsl] XSLT code for XML to JSON conversion?

2019-12-13 04:27:03
However, the xml-to-json function on XSLT 3.0 doesn't convert arbitrary XML to 
JSON; it requires you first to do a transformation to the XML structure that 
reflects the JSON you want to produce.

Generally, off-the-shelf tools that convert arbitrary XML to JSON tend to 
produce JSON that's not very nice to work with.

Michael Kay
Saxonica

On 13 Dec 2019, at 10:12, O'Neil Delpratt oneil(_at_)saxonica(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi,

Saxon on the Java Platform would work fine on the command-line, but as Liam 
said you have the Java runtime startup.

Alternatively Saxon/C could equally fit your requirements. It is cross 
compiled to native library, which can be run on the command-line using C/C++. 
Saxon/C also comes with Python extension API.

kind regards,

O'Neil


On 12 Dec 2019, at 22:37, Steven D. Majewski 
steve(_dot_)majewski(_at_)gmail(_dot_)com 
<mailto:steve(_dot_)majewski(_at_)gmail(_dot_)com> 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> wrote:

There are also non XSLT converters that use SAX: read XML and serialize out 
as JSON. 

There are several node-js packages.
Python xmljson. https://pypi.org/project/xmljson/ 
<https://pypi.org/project/xmljson/> supports several different JSON encoding 
conventions.  

And I’m sure many others.  
( I’ve used the Python package, but not for any large projects.  )

— Steve. 


On Dec 12, 2019, at 5:09 PM, Liam R. E. Quin 
liam(_at_)fromoldbooks(_dot_)org <mailto:liam(_at_)fromoldbooks(_dot_)org> 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> wrote:

On Thu, 2019-12-12 at 21:32 +0000, Richard Fozzard
richard(_dot_)fozzard(_at_)noaa(_dot_)gov 
<mailto:richard(_dot_)fozzard(_at_)noaa(_dot_)gov> wrote:
Hi Folks,

We're looking to do conversion of relatively complex XML (i.e. 
namespaces, attributes, repeating elements, xlinks) into JSON from
the 
Unix command line to build a web page. We've  used the XML to JSON 
feature in the Oxygen Developer tool, and it works well, but that's
a 
GUI, not a command line tool.

It's probably using XSLT under the hood, with a stylesheet that's
usable e.g. with Saxon. You do pay the penalty of Java runtime startup,
though.

Note also that XSLT 3 includes a standard function to produce JSON; see
https://www.w3.org/TR/xpath-functions-31/#json-to-xml-mapping 
<https://www.w3.org/TR/xpath-functions-31/#json-to-xml-mapping>

So you could just use xml-to-json() in XSLT. You may need Saxon EE for
that, i'm not sure offhand.

Of course, you could also just send XML to the Web client; what you are
doing by using a complex transformation into JSON is moving the
complexity from one developer to another. You could also generate HTML
on the server, whic might make it easier to meet 508/WCAG requirements
:)

Liam

-- 
Liam Quin, https://www.delightfulcomputing.com/ 
<https://www.delightfulcomputing.com/>
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org 
<http://www.fromoldbooks.org/>


XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/1363285> (by 
email <applewebdata://6BDE66D7-3B12-4981-9CA2-7BDD7B8FA156>)

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by 
email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>