nverwer / xslt-json-parser

XSLT 2.0 JSON parser for the json.org dialect

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

xslt-json-parser

XSLT 2.0 JSON parser for the json.org dialect.

Example usage:

The XML file

<?xml version="1.0" encoding="utf-8"?>
<data>{"myArray": [null, true, false, "A String", 1234.1234], "Another pair": true}</data>

The XSL file

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:j="urn:xslt-json-parser:json-parser">
    
    <xsl:output indent="yes"/>
    
    <xsl:import href="json-parser.xsl"/>
    
    <xsl:template match="/">
        <xsl:copy-of select="j:parse-json(data)"/>
    </xsl:template>
</xsl:stylesheet>

The result:

<?xml version="1.0" encoding="utf-8"?>
<object>
    <pair name="myArray">
        <array>
            <null/>
            <boolean>true</boolean>
            <boolean>false</boolean>
            <string>A String</string>
            <number>1234.1234</number>
        </array>
    </pair>
    <pair name="Another pair">
        <boolean>true</boolean>
    </pair>
</object>

About

XSLT 2.0 JSON parser for the json.org dialect

License:MIT License


Languages

Language:XSLT 100.0%