annotate xslt/json.xsl @ 13:197a850b1f6f default tip

working version of xml2json transformation
author cin
date Mon, 09 Apr 2018 16:27:26 +0300
parents 191b81b2052b
children
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"
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
5 xmlns:exsl="http://exslt.org/common">
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
6 <xsl:output method="text" />
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
7
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
8 <xsl:template match="/">
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
9 <xsl:apply-templates mode="json-value" />
0
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
10 </xsl:template>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
11
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
12
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
13 <!-- handle json-object -->
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
14
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
15 <xsl:template match="*" mode="json-object">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
16 <xsl:call-template name="write-members"/>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
17 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
18
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
19 <xsl:template match="*|@*" mode="json-member">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
20 <xsl:param name="values" select="."/>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
21 <xsl:call-template name="write-string">
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
22 <xsl:with-param name="text"><xsl:apply-templates select="." mode="json-member-name"/></xsl:with-param>
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
23 </xsl:call-template>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
24 <xsl:text> : </xsl:text>
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
25 <xsl:apply-templates select="." mode="json-member-value">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
26 <xsl:with-param name="values" select="$values"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
27 </xsl:apply-templates>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
28 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
29
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
30 <xsl:template match="*" mode="json-member-name">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
31 <xsl:value-of select="local-name(.)"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
32 </xsl:template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
33
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
34 <xsl:template match="@*" mode="json-member-name">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
35 <xsl:value-of select="concat('_',local-name(.))"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
36 </xsl:template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
37
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
38 <xsl:template match="*|@*" mode="json-member-value">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
39 <xsl:param name="values" select="."/>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
40 <xsl:choose>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
41 <xsl:when test="count($values) > 1">
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
42 <xsl:call-template name="write-array">
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
43 <xsl:with-param name="values" select="$values"/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
44 </xsl:call-template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
45 </xsl:when>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
46 <xsl:otherwise>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
47 <xsl:apply-templates select="$values" mode="json-value"/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
48 </xsl:otherwise>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
49 </xsl:choose>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
50 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
51
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
52 <xsl:template match="*|@*" mode="json-array-item">
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
53 <xsl:apply-templates select="." mode="json-value"/>
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
54 <xsl:if test="position() != last()">
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
55 <xsl:text>, </xsl:text>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
56 </xsl:if>
0
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
57 </xsl:template>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
58
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
59 <!-- handle json-value -->
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
60
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
61 <xsl:template match="text()[. = 'true'] | @*[. = 'true']" mode="json-value">
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
62 <xsl:text>true</xsl:text>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
63 </xsl:template>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
64
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
65 <xsl:template match="text()[. = 'false'] | @*[. = 'false']"
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
66 mode="json-value">
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
67 <xsl:text>false</xsl:text>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
68 </xsl:template>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
69
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
70 <xsl:template match="text()[string(number(.)) != 'NaN'] | @*[string(number(.)) != 'NaN']"
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
71 mode="json-value">
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
72 <xsl:value-of select="number(.)" />
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
73 </xsl:template>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
74
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
75 <xsl:template match="text()|@*" mode="json-value">
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
76 <xsl:call-template name="write-string">
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
77 <xsl:with-param name="text" select="."/>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
78 </xsl:call-template>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
79 </xsl:template>
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
80
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
81 <xsl:template match="*[boolean(* | @*) or not(text())]" mode="json-value">
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
82 <xsl:call-template name="write-object"/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
83 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
84
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
85 <xsl:template match="*[@xsi:nil = 'true']" mode="json-value">
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
86 <xsl:text>null</xsl:text>
0
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
87 </xsl:template>
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
88
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
89 <!-- template traits -->
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
90
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
91 <xsl:template name="write-value">
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
92 <xsl:param name="value" select="."/>
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
93 <xsl:apply-templates select="$value" mode="json-value"/>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
94 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
95
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
96 <xsl:template name="write-member">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
97 <xsl:param name="name"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
98 <xsl:param name="value"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
99 <xsl:call-template name="write-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
100 <xsl:with-param name="text" select="$name"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
101 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
102 <xsl:text> : </xsl:text>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
103 <xsl:apply-templates select="$value" mode="json-value"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
104 </xsl:template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
105
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
106 <xsl:template name="write-member-string">
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
107 <xsl:param name="name"/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
108 <xsl:param name="value"/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
109 <xsl:call-template name="write-string">
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
110 <xsl:with-param name="text" select="$name"/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
111 </xsl:call-template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
112 <xsl:text> : </xsl:text>
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
113 <xsl:call-template name="write-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
114 <xsl:with-param name="text" select="$value"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
115 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
116 </xsl:template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
117
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
118 <xsl:template name="write-member-array">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
119 <xsl:param name="name"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
120 <xsl:param name="values"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
121 <xsl:call-template name="write-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
122 <xsl:with-param name="text" select="$name"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
123 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
124 <xsl:text> : </xsl:text>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
125 <xsl:call-template name="write-array">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
126 <xsl:with-param name="values" select="$values"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
127 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
128 </xsl:template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
129
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
130 <xsl:template name="write-separator">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
131 <xsl:text>, </xsl:text>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
132 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
133
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
134 <!-- specialized template traits -->
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
135
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
136 <xsl:template name="write-string">
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
137 <xsl:param name="text"/>
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
138 <xsl:text>&quot;</xsl:text>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
139 <xsl:call-template name="escape-bs-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
140 <xsl:with-param name="s" select="$text"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
141 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
142 <xsl:text>&quot;</xsl:text>
0
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
143 </xsl:template>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
144
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
145 <xsl:template name="write-object">
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
146 <xsl:param name="value" select="."/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
147 <xsl:text>{ </xsl:text>
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
148 <xsl:apply-templates select="$value" mode="json-object"/>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
149 <xsl:text> }</xsl:text>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
150 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
151
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
152 <xsl:template name="write-array">
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
153 <xsl:param name="values"/>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
154
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
155 <xsl:text>[ </xsl:text>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
156 <xsl:apply-templates select="$values" mode="json-array-item"/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
157 <xsl:text> ]</xsl:text>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
158 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
159
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
160 <xsl:template name="write-members">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
161 <xsl:param name="members" select="*"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
162
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
163 <xsl:for-each select="$members">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
164 <xsl:variable name="current" select="."/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
165 <xsl:variable name="values" select="$members[local-name(.) = local-name($current)]"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
166 <xsl:if test="generate-id($current) = generate-id($values)">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
167 <xsl:if test="position()>1">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
168 <xsl:call-template name="write-separator"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
169 </xsl:if>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
170 <xsl:apply-templates select="$current" mode="json-member">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
171 <xsl:with-param name="values" select="$values"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
172 </xsl:apply-templates>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
173 </xsl:if>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
174 </xsl:for-each>
191b81b2052b first version of the xslt transform from xml to json
cin
parents: 11
diff changeset
175 </xsl:template>
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
176
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
177 <!-- escape string -->
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
178 <!--
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
179 Copyright (c) 2006,2008 Doeke Zanstra
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
180 All rights reserved.
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
181 https://github.com/doekman/xml2json-xslt/blob/master/xml2json.xslt
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
182 -->
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
183 <!-- Escape the backslash (\) before everything else. -->
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
184 <xsl:template name="escape-bs-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
185 <xsl:param name="s"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
186 <xsl:choose>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
187 <xsl:when test="contains($s,'\')">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
188 <xsl:call-template name="escape-quot-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
189 <xsl:with-param name="s" select="concat(substring-before($s,'\'),'\\')"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
190 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
191 <xsl:call-template name="escape-bs-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
192 <xsl:with-param name="s" select="substring-after($s,'\')"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
193 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
194 </xsl:when>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
195 <xsl:otherwise>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
196 <xsl:call-template name="escape-quot-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
197 <xsl:with-param name="s" select="$s"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
198 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
199 </xsl:otherwise>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
200 </xsl:choose>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
201 </xsl:template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
202
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
203 <!-- Escape the double quote ("). -->
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
204 <xsl:template name="escape-quot-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
205 <xsl:param name="s"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
206 <xsl:choose>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
207 <xsl:when test="contains($s,'&quot;')">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
208 <xsl:call-template name="encode-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
209 <xsl:with-param name="s" select="concat(substring-before($s,'&quot;'),'\&quot;')"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
210 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
211 <xsl:call-template name="escape-quot-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
212 <xsl:with-param name="s" select="substring-after($s,'&quot;')"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
213 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
214 </xsl:when>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
215 <xsl:otherwise>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
216 <xsl:call-template name="encode-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
217 <xsl:with-param name="s" select="$s"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
218 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
219 </xsl:otherwise>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
220 </xsl:choose>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
221 </xsl:template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
222
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
223 <!-- Replace tab, line feed and/or carriage return by its matching escape code. Can't escape backslash
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
224 or double quote here, because they don't replace characters (&#x0; becomes \t), but they prefix
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
225 characters (\ becomes \\). Besides, backslash should be seperate anyway, because it should be
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
226 processed first. This function can't do that. -->
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
227 <xsl:template name="encode-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
228 <xsl:param name="s"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
229 <xsl:choose>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
230 <!-- tab -->
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
231 <xsl:when test="contains($s,'&#x9;')">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
232 <xsl:call-template name="encode-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
233 <xsl:with-param name="s" select="concat(substring-before($s,'&#x9;'),'\t',substring-after($s,'&#x9;'))"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
234 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
235 </xsl:when>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
236 <!-- line feed -->
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
237 <xsl:when test="contains($s,'&#xA;')">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
238 <xsl:call-template name="encode-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
239 <xsl:with-param name="s" select="concat(substring-before($s,'&#xA;'),'\n',substring-after($s,'&#xA;'))"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
240 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
241 </xsl:when>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
242 <!-- carriage return -->
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
243 <xsl:when test="contains($s,'&#xD;')">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
244 <xsl:call-template name="encode-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
245 <xsl:with-param name="s" select="concat(substring-before($s,'&#xD;'),'\r',substring-after($s,'&#xD;'))"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
246 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
247 </xsl:when>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
248 <xsl:otherwise><xsl:value-of select="$s"/></xsl:otherwise>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
249 </xsl:choose>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
250 </xsl:template>
11
14162f9133a1 working on xml to json transform
cin
parents: 0
diff changeset
251
0
cbdada054b4a Basic schemas for generating csharp internal dom from model definition
cin
parents:
diff changeset
252 </xsl:stylesheet>