annotate xslt/json-person.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
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
1 <xsl:stylesheet version="1.0"
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
4 xmlns:exsl="http://exslt.org/common">
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
5 <xsl:import href="json.xsl"/>
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
6 <xsl:output method="text" />
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
7
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
8 <xsl:template match="firstName | lastName" mode="json-member-value">
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
9 <xsl:param name="values" select="."/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
10 <xsl:call-template name="write-array">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
11 <xsl:with-param name="values" select="$values"/>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
12 </xsl:call-template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
13 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
14
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
15 <xsl:template match="address | work | home" mode="json-object">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
16 <xsl:call-template name="write-member-string">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
17 <xsl:with-param name="name" select="'_type'"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
18 <xsl:with-param name="value" select="local-name(.)"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
19 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
20
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
21 <xsl:variable name="members" select="@order | *"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
22 <xsl:if test="$members">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
23 <xsl:call-template name="write-separator"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
24 <xsl:call-template name="write-members">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
25 <xsl:with-param name="members" select="$members"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
26 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
27 </xsl:if>
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
28 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
29
13
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
30 <xsl:template match="person" mode="json-object">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
31 <xsl:variable name="address" select="home | work | address"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
32 <xsl:variable name="members" select="*[not(self::home | self::work | self::address)]"/>
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:if test="$address">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
35 <xsl:call-template name="write-member-array">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
36 <xsl:with-param name="name" select="'address'"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
37 <xsl:with-param name="values" select="$address"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
38 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
39 </xsl:if>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
40
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
41 <xsl:if test="count($address) > 0 and count($members) > 0">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
42 <xsl:call-template name="write-separator"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
43 </xsl:if>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
44
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
45 <xsl:call-template name="write-members">
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
46 <xsl:with-param name="members" select="$members"/>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
47 </xsl:call-template>
197a850b1f6f working version of xml2json transformation
cin
parents: 12
diff changeset
48
12
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
49 </xsl:template>
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
50
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
51
191b81b2052b first version of the xslt transform from xml to json
cin
parents:
diff changeset
52 </xsl:stylesheet>