Mercurial > pub > ModelGenerator
annotate xslt/json.xsl @ 11:14162f9133a1
working on xml to json transform
author | cin |
---|---|
date | Sun, 08 Apr 2018 23:30:11 +0300 |
parents | cbdada054b4a |
children | 191b81b2052b |
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" |
11 | 3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
5 <xsl:output method="text" /> | |
6 | |
7 <xsl:template match="*[count(*) = 0]"> | |
8 <xsl:apply-templates mode="json-value" /> | |
9 </xsl:template> | |
10 | |
11 <xsl:template match="*[count(*) > 0]"> | |
12 <xsl:text>{ </xsl:text> | |
13 <xsl:apply-templates mode="json-object-member"/> | |
14 <xsl:text> }</xsl:text> | |
0
cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff
changeset
|
15 </xsl:template> |
cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff
changeset
|
16 |
11 | 17 <xsl:template match="text()"/> |
18 | |
19 <!-- handle json-object --> | |
20 | |
21 <xsl:template name="write-object"> | |
22 | |
23 </xsl:template> | |
24 | |
25 <xsl:template match="*" mode="json-object-member"> | |
26 <xsl:call-template name="write-json-string"> | |
27 <xsl:with-param name="text" select="local-name(.)"/> | |
28 </xsl:call-template> | |
29 <xsl:text> : </xsl:text> | |
30 <xsl:apply-templates mode="json-value"/> | |
31 <xsl:if test="position() != last()"> | |
32 <xsl:text>, </xsl:text> | |
33 </xsl:if> | |
0
cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff
changeset
|
34 </xsl:template> |
cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff
changeset
|
35 |
11 | 36 <!-- handle json-value --> |
37 | |
38 <xsl:template match="*[@xsi:nil = 'true']"> | |
39 <xsl:text>null</xsl:text> | |
40 </xsl:template> | |
41 | |
42 <xsl:template match="text()[. = 'true']" mode="json-value"> | |
43 <xsl:text>true</xsl:text> | |
44 </xsl:template> | |
45 | |
46 <xsl:template match="text()[. = 'false']" | |
47 mode="json-value"> | |
48 <xsl:text>false</xsl:text> | |
49 </xsl:template> | |
50 | |
51 <xsl:template match="text()[string(number(.)) != 'NaN']" | |
52 mode="json-value"> | |
53 <xsl:value-of select="number(.)" /> | |
54 </xsl:template> | |
55 | |
56 <xsl:template match="text()" mode="json-value"> | |
57 <xsl:call-template name="write-json-string"> | |
58 <xsl:with-param name="text" select="."/> | |
59 </xsl:call-template> | |
60 </xsl:template> | |
61 | |
62 <xsl:template match="*" mode="json-value"> | |
63 <xsl:apply-templates select="."/> | |
0
cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff
changeset
|
64 </xsl:template> |
cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff
changeset
|
65 |
11 | 66 <!-- template traits --> |
67 <xsl:template name="write-json-string"> | |
68 <xsl:param name="text"/> | |
69 <xsl:value-of select="concat('"', $text,'"')" /> | |
0
cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff
changeset
|
70 </xsl:template> |
11 | 71 |
0
cbdada054b4a
Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff
changeset
|
72 </xsl:stylesheet> |