annotate xslt/preprocess.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 d240adc2ac70
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
1 <?xml version="1.0" encoding="utf-8"?>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
2 <xsl:stylesheet version="1.0"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
4 xmlns:m="http://implab.org/schemas/data-model.v1.xsd"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
5 xmlns:exsl="http://exslt.org/common"
4
cin
parents: 2
diff changeset
6 xmlns:msxsl="urn:schemas-microsoft-com:xslt"
2
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
7 xmlns:t="http://implab.org/schemas/temp"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
8 >
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
9 <!--
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
10 This template provides 'module' variable which is the
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
11 result of processing imports from packages.
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
12
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
13 Variable $module is a node set created from the result-tree
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
14 which is the result of applying templates in mode=preprocess
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
15 -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
16 <xsl:output method="xml" indent="yes" />
4
cin
parents: 2
diff changeset
17
cin
parents: 2
diff changeset
18 <msxsl:script language="JScript" implements-prefix="exsl">
cin
parents: 2
diff changeset
19 this['node-set'] = function (x) {
cin
parents: 2
diff changeset
20 return x;
cin
parents: 2
diff changeset
21 }
cin
parents: 2
diff changeset
22 </msxsl:script>
cin
parents: 2
diff changeset
23
2
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
24 <xsl:variable name="preprocessResult">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
25 <t:module>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
26 <xsl:call-template name="preprocess" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
27 </t:module>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
28 </xsl:variable>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
29 <xsl:variable name="module" select="exsl:node-set($preprocessResult)/t:module"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
30
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
31 <xsl:template name="preprocess">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
32 <xsl:param name="root" select="/" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
33 <xsl:param name="pending" select="$root/m:package/m:import[@href]" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
34 <xsl:param name="seen" select="/.." />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
35 <xsl:param name="file" select="''" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
36 <xsl:param name="primary" select="true()" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
37
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
38 <xsl:if test="not($seen[generate-id() = generate-id($root)])">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
39 <xsl:apply-templates select="$root" mode="preprocess">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
40 <xsl:with-param name="primary" select="$primary" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
41 <xsl:with-param name="file" select="$file" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
42 </xsl:apply-templates>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
43 <xsl:if test="$pending">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
44 <xsl:variable name="doc" select="document($pending[1]/@href)" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
45 <xsl:call-template name="preprocess">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
46 <xsl:with-param name="root" select="$doc" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
47 <xsl:with-param name="file" select="$pending[1]/@href" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
48 <xsl:with-param name="pending"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
49 select="$pending[position() > 1] | $doc/m:package/m:import[@href]" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
50 <xsl:with-param name="seen" select="$root | $seen" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
51 <xsl:with-param name="primary" select="false()" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
52 </xsl:call-template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
53 </xsl:if>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
54 </xsl:if>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
55 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
56
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
57 <xsl:template match="m:package" mode="preprocess">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
58 <xsl:param name="primary" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
59 <xsl:param name="file" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
60 <xsl:copy>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
61 <xsl:copy-of select="@*" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
62 <xsl:if test="$primary">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
63 <xsl:attribute name="primary"><xsl:value-of select="$primary" /></xsl:attribute>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
64 </xsl:if>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
65 <xsl:if test="$file">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
66 <xsl:attribute name="file"><xsl:value-of select="$file" /></xsl:attribute>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
67 </xsl:if>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
68 <xsl:apply-templates mode="preprocess">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
69 <xsl:with-param name="primary" select="$primary" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
70 <xsl:with-param name="file" select="$file" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
71 </xsl:apply-templates>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
72 </xsl:copy>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
73 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
74
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
75 <xsl:template match="*|/" mode="preprocess">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
76 <xsl:param name="primary" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
77 <xsl:param name="file" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
78 <xsl:copy>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
79 <xsl:copy-of select="@*" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
80 <xsl:apply-templates mode="preprocess">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
81 <xsl:with-param name="primary" select="$primary" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
82 <xsl:with-param name="file" select="$file" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
83 </xsl:apply-templates>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
84 </xsl:copy>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
85 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
86 </xsl:stylesheet>