Mercurial > pub > ModelGenerator
comparison xslt/json.xsl @ 0:cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
| author | cin |
|---|---|
| date | Wed, 21 Feb 2018 03:01:53 +0300 |
| parents | |
| children | 14162f9133a1 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:cbdada054b4a |
|---|---|
| 1 <?xml version="1.0" encoding="UTF-8"?> | |
| 2 <xsl:stylesheet version="1.0" | |
| 3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
| 4 <xsl:output method="text"/> | |
| 5 | |
| 6 <xsl:template match="/"> | |
| 7 <xsl:apply-templates mode="json-array" /> | |
| 8 </xsl:template> | |
| 9 | |
| 10 <xsl:template match="*" mode="json-array"> | |
| 11 [ | |
| 12 <xsl:for-each select="*"> | |
| 13 <xsl:apply-templates select="." mode="json-value"/> | |
| 14 <xsl:if test="position() != last()">,</xsl:if> | |
| 15 </xsl:for-each> | |
| 16 ] | |
| 17 </xsl:template> | |
| 18 | |
| 19 <xsl:template match="*[count(*) != 0]" mode="json-array-item"> | |
| 20 "<xsl:value-of select="name()"/> : <xsl:apply-templates mode="json-value"/>" | |
| 21 <xsl:if test="position() != last()">,</xsl:if> | |
| 22 </xsl:template> | |
| 23 | |
| 24 <xsl:template match="*" mode="json-value"> | |
| 25 <xsl:choose> | |
| 26 <xsl:when test="count(*) != 0">{ <xsl:apply-templates mode="json-named-value" /> }</xsl:when> | |
| 27 <xsl:when test="text() = 'true'">true</xsl:when> | |
| 28 <xsl:when test="text() = 'false'">false</xsl:when> | |
| 29 <xsl:when test="text() = 'null'">null</xsl:when> | |
| 30 <xsl:when test="string(number(.)) != 'NaN'"><xsl:value-of select="number(.)"/></xsl:when> | |
| 31 <xsl:otherwise>"<xsl:value-of select="text()"/>"</xsl:otherwise> | |
| 32 </xsl:choose> | |
| 33 </xsl:template> | |
| 34 | |
| 35 <xsl:template match="*" mode="json-named-value"> | |
| 36 <xsl:value-of select="name()"/> : <xsl:apply-templates select="." mode="json-value"/> | |
| 37 </xsl:template> | |
| 38 </xsl:stylesheet> |
