annotate Implab/Xml/json.xsl @ 269:ff581cff7003 v3

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