annotate xslt/json.xsl @ 3:437127ab6a12

non-working version separate common model templates from csharp templates, plans to support complex primary and foreign keys
author cin
date Wed, 28 Feb 2018 02:10:29 +0300
parents cbdada054b4a
children 14162f9133a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
1 <?xml version="1.0" encoding="UTF-8"?>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
2 <xsl:stylesheet version="1.0"
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
4 <xsl:output method="text"/>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
5
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
6 <xsl:template match="/">
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
7 <xsl:apply-templates mode="json-array" />
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
8 </xsl:template>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
9
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
10 <xsl:template match="*" mode="json-array">
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
11 [
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
12 <xsl:for-each select="*">
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
13 <xsl:apply-templates select="." mode="json-value"/>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
14 <xsl:if test="position() != last()">,</xsl:if>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
15 </xsl:for-each>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
16 ]
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
17 </xsl:template>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
18
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
19 <xsl:template match="*[count(*) != 0]" mode="json-array-item">
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
20 "<xsl:value-of select="name()"/> : <xsl:apply-templates mode="json-value"/>"
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
21 <xsl:if test="position() != last()">,</xsl:if>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
22 </xsl:template>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
23
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
24 <xsl:template match="*" mode="json-value">
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
25 <xsl:choose>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
26 <xsl:when test="count(*) != 0">{ <xsl:apply-templates mode="json-named-value" /> }</xsl:when>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
27 <xsl:when test="text() = 'true'">true</xsl:when>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
28 <xsl:when test="text() = 'false'">false</xsl:when>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
29 <xsl:when test="text() = 'null'">null</xsl:when>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
30 <xsl:when test="string(number(.)) != 'NaN'"><xsl:value-of select="number(.)"/></xsl:when>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
31 <xsl:otherwise>"<xsl:value-of select="text()"/>"</xsl:otherwise>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
32 </xsl:choose>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
33 </xsl:template>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
34
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
35 <xsl:template match="*" mode="json-named-value">
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
36 <xsl:value-of select="name()"/> : <xsl:apply-templates select="." mode="json-value"/>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
37 </xsl:template>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
38 </xsl:stylesheet>