-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonify.xsl
24 lines (14 loc) · 979 Bytes
/
jsonify.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">{<xsl:apply-templates select="*" />}
</xsl:template>
<xsl:template match="*">"<xsl:value-of select="name(.)" />":{<xsl:apply-templates select="*|@*" />},</xsl:template>
<xsl:template match="*[not(following-sibling::*)]">"<xsl:value-of select="name(.)" />":{<xsl:apply-templates />}</xsl:template>
<xsl:template match="//*[not(child::*)]">"<xsl:value-of select="name(.)" />":<xsl:apply-templates />,</xsl:template>
<xsl:template match="//*[not(child::*) and not(following-sibling::*)]">"<xsl:value-of select="name(.)" />":<xsl:apply-templates /></xsl:template>
<xsl:template match="text()">"<xsl:value-of select="." />"</xsl:template>
<xsl:template match="@*"></xsl:template>
</xsl:stylesheet>