diff xslt/json-person.xsl @ 12:191b81b2052b

first version of the xslt transform from xml to json
author cin
date Mon, 09 Apr 2018 06:43:46 +0300
parents
children 197a850b1f6f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xslt/json-person.xsl	Mon Apr 09 06:43:46 2018 +0300
@@ -0,0 +1,31 @@
+<xsl:stylesheet version="1.0"
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:exsl="http://exslt.org/common">
+	<xsl:import href="json.xsl"/>
+	<xsl:output method="text" />
+	
+	<xsl:template match="firstName | lastName" mode="json-member-value">
+		<xsl:call-template name="write-value">
+			<xsl:with-param name="value" select="key('members',concat(generate-id(..),local-name(.)))[last()]"/>
+		</xsl:call-template>
+	</xsl:template>
+	
+	<xsl:template match="address" mode="json-member-value">
+		<xsl:call-template name="write-array"/>
+	</xsl:template>
+	
+	<xsl:template match="work | home">
+		<address>
+			<_type><xsl:value-of select="local-name(.)"/></_type>
+			<xsl:copy-of select="*"/>
+		</address>
+	</xsl:template>
+	
+	<xsl:template match="@*">
+		<xsl:element name="{local-name(.)}" >
+			<xsl:value-of select="."/>
+		</xsl:element>
+	</xsl:template>
+	
+</xsl:stylesheet>
\ No newline at end of file