comparison 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
comparison
equal deleted inserted replaced
12:191b81b2052b 13:197a850b1f6f
4 xmlns:exsl="http://exslt.org/common"> 4 xmlns:exsl="http://exslt.org/common">
5 <xsl:import href="json.xsl"/> 5 <xsl:import href="json.xsl"/>
6 <xsl:output method="text" /> 6 <xsl:output method="text" />
7 7
8 <xsl:template match="firstName | lastName" mode="json-member-value"> 8 <xsl:template match="firstName | lastName" mode="json-member-value">
9 <xsl:call-template name="write-value"> 9 <xsl:param name="values" select="."/>
10 <xsl:with-param name="value" select="key('members',concat(generate-id(..),local-name(.)))[last()]"/> 10 <xsl:call-template name="write-array">
11 <xsl:with-param name="values" select="$values"/>
11 </xsl:call-template> 12 </xsl:call-template>
12 </xsl:template> 13 </xsl:template>
13 14
14 <xsl:template match="address" mode="json-member-value"> 15 <xsl:template match="address | work | home" mode="json-object">
15 <xsl:call-template name="write-array"/> 16 <xsl:call-template name="write-member-string">
17 <xsl:with-param name="name" select="'_type'"/>
18 <xsl:with-param name="value" select="local-name(.)"/>
19 </xsl:call-template>
20
21 <xsl:variable name="members" select="@order | *"/>
22 <xsl:if test="$members">
23 <xsl:call-template name="write-separator"/>
24 <xsl:call-template name="write-members">
25 <xsl:with-param name="members" select="$members"/>
26 </xsl:call-template>
27 </xsl:if>
16 </xsl:template> 28 </xsl:template>
17 29
18 <xsl:template match="work | home"> 30 <xsl:template match="person" mode="json-object">
19 <address> 31 <xsl:variable name="address" select="home | work | address"/>
20 <_type><xsl:value-of select="local-name(.)"/></_type> 32 <xsl:variable name="members" select="*[not(self::home | self::work | self::address)]"/>
21 <xsl:copy-of select="*"/> 33
22 </address> 34 <xsl:if test="$address">
35 <xsl:call-template name="write-member-array">
36 <xsl:with-param name="name" select="'address'"/>
37 <xsl:with-param name="values" select="$address"/>
38 </xsl:call-template>
39 </xsl:if>
40
41 <xsl:if test="count($address) > 0 and count($members) > 0">
42 <xsl:call-template name="write-separator"/>
43 </xsl:if>
44
45 <xsl:call-template name="write-members">
46 <xsl:with-param name="members" select="$members"/>
47 </xsl:call-template>
48
23 </xsl:template> 49 </xsl:template>
24 50
25 <xsl:template match="@*">
26 <xsl:element name="{local-name(.)}" >
27 <xsl:value-of select="."/>
28 </xsl:element>
29 </xsl:template>
30 51
31 </xsl:stylesheet> 52 </xsl:stylesheet>