Skip to content

Latest commit

 

History

History
52 lines (41 loc) · 1.05 KB

README.md

File metadata and controls

52 lines (41 loc) · 1.05 KB

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>