annotate xslt/model.xsl @ 6:1f4009d4afb6

working on model to csharp transform
author cin
date Mon, 05 Mar 2018 10:37:47 +0300
parents d240adc2ac70
children 3fe157be5141
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" xmlns:m="http://implab.org/schemas/data-model.v1.xsd"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
4 xmlns:clr="http://implab.org/schemas/data-model/dotnet.v1.xsd"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
5 xmlns:cs="http://implab.org/schemas/code-dom/csharp.v1.xsd" xmlns:sql="http://implab.org/schemas/data-model/sql.v1.xsd"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
6 xmlns:t="http://implab.org/schemas/temp" xmlns:exsl="http://exslt.org/common"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
7 exclude-result-prefixes="clr m xsl exsl sql">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
8
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
9 <xsl:import href="preprocess.xsl" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
10 <xsl:include href="text-tools.xsl"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
11
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
12 <xsl:output method="xml" indent="yes" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
13
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
14 <xsl:key name="type" match="m:package/m:*" use="@name" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
15
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
16 <xsl:template match="/">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
17 <cs:document>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
18 <xsl:apply-templates select="$module" mode="document" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
19 </cs:document>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
20 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
21
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
22 <!-- code generation -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
23
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
24 <!-- disable default template -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
25 <xsl:template match="*|text()" mode="document" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
26
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
27 <xsl:template match="t:module" mode="document">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
28 <xsl:apply-templates mode="document" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
29 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
30
3
437127ab6a12 non-working version
cin
parents: 2
diff changeset
31
2
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
32
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
33 <!-- member resolution traits -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
34
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
35 <!-- Resolves members using given criteria
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
36 @param type
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
37 the name of the type whose members are inspected
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
38 @param memberName
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
39 the name of the member to lookup
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
40 @param scope
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
41 the scope where to look (members, properties, keys, relations)
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
42
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
43 This template recursively inspects the given type down to it's inheritance
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
44 hierarchy and outputs members matching criteria.
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
45 -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
46 <xsl:template name="getMembers">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
47 <xsl:param name="type"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
48 <xsl:param name="memberName" select="''"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
49 <xsl:param name="scope" select="'members'"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
50 <!-- prevents cyclic references -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
51 <xsl:param name="seen" select="/.."/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
52 <xsl:for-each select="$module">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
53 <xsl:apply-templates select="key('type', $type)"
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
54 mode="lookup-members">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
55 <xsl:with-param name="memberName" select="$memberName"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
56 <xsl:with-param name="scope" select="$scope"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
57 <xsl:with-param name="seen" select="$seen"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
58 </xsl:apply-templates>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
59 </xsl:for-each>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
60 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
61
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
62 <xsl:template match="*" mode="lookup-members"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
63
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
64 <xsl:template match="m:entity" mode="lookup-members">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
65 <xsl:param name="memberName" select="''"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
66 <xsl:param name="scope" select="'members'"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
67 <xsl:param name="seen"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
68
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
69 <xsl:variable name="self" select="."/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
70
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
71 <xsl:if test="not($seen[generate-id() = generate-id($self)])">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
72 <xsl:variable name="scopeMembers">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
73 <xsl:call-template name="selectScopeMembers">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
74 <xsl:with-param name="scope" select="$scope"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
75 </xsl:call-template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
76 </xsl:variable>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
77
6
1f4009d4afb6 working on model to csharp transform
cin
parents: 4
diff changeset
78 <xsl:variable name="members" select="exsl:node-set($scopeMembers)/*[not($memberName) or @name=$memberName]"/>
2
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
79
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
80 <xsl:choose>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
81 <xsl:when test="$members">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
82 <xsl:copy-of select="$members"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
83 </xsl:when>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
84 <xsl:when test="m:extends">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
85 <xsl:call-template name="getMembers">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
86 <xsl:with-param name="type" select="m:extends/@type"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
87 <xsl:with-param name="memberName" select="$memberName"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
88 <xsl:with-param name="scope" select="$scope"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
89 <xsl:with-param name="seen" select="$seen | $self"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
90 </xsl:call-template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
91 </xsl:when>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
92 <xsl:otherwise>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
93 <xsl:call-template name="warn">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
94 <xsl:with-param name="msg">
6
1f4009d4afb6 working on model to csharp transform
cin
parents: 4
diff changeset
95 <t:trace msg="failed to resolve {$memberName}, scope={$scope}"/>
2
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
96 <t:trace msg="inspected classes">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
97 <xsl:for-each select="$seen | $self">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
98 <t:trace msg="{name()} {@name}"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
99 </xsl:for-each>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
100 </t:trace>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
101 </xsl:with-param>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
102 </xsl:call-template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
103 </xsl:otherwise>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
104 </xsl:choose>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
105 </xsl:if>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
106 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
107
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
108 <!-- this template implements scope filtering -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
109 <xsl:template name="selectScopeMembers">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
110 <xsl:param name="scope" select="'members'"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
111 <xsl:choose>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
112 <xsl:when test="$scope='members'">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
113 <xsl:apply-templates mode="filter-members"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
114 </xsl:when>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
115 <xsl:when test="$scope='keys'">
6
1f4009d4afb6 working on model to csharp transform
cin
parents: 4
diff changeset
116 <xsl:apply-templates mode="filter-keys"/>
2
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
117 </xsl:when>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
118 <xsl:when test="$scope='properties'">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
119 <xsl:apply-templates mode="fiflter-properties"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
120 </xsl:when>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
121 <xsl:when test="$scope='relations'">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
122 <xsl:apply-templates mode="fiflter-relations"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
123 </xsl:when>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
124 </xsl:choose>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
125 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
126
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
127 <!-- filter-members -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
128 <xsl:template match="*|text()" mode="filter-members"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
129 <xsl:template match="*[@name]" mode="filter-members">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
130 <xsl:copy>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
131 <xsl:copy-of select="@*" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
132 <xsl:attribute name="declaringType"><xsl:value-of select="../@name" /></xsl:attribute>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
133 <xsl:copy-of select="*" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
134 </xsl:copy>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
135 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
136
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
137 <!-- filter-keys -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
138 <xsl:template match="*|text()" mode="filter-keys"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
139 <xsl:template match="m:primaryKey" mode="filter-keys">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
140 <xsl:apply-templates select="." mode="filter-members"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
141 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
142
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
143 <!-- filter-properties -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
144 <xsl:template match="*|text()" mode="filter-properties"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
145 <xsl:template match="m:property" mode="filter-properties">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
146 <xsl:apply-templates select="." mode="filter-members"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
147 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
148
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
149 <!-- filter-relations -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
150 <xsl:template match="*|text()" mode="filter-relations"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
151 <xsl:template match="m:hasA | m:hasMany" mode="filter-relations">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
152 <xsl:apply-templates select="." mode="filter-members"/>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
153 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
154
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
155
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
156
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
157 <!-- Resolves primaryKey information for the given type name.
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
158 @returns m:primaryKey node copy with additional attribute
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
159 @declaringType which points to the type where this primaryKey
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
160 was defined.
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
161 -->
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
162 <xsl:template name="getPrimaryKey">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
163 <xsl:param name="type" />
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
164 <xsl:call-template name="getMembers">
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
165 <xsl:with-param name="type" select="$type"/>
6
1f4009d4afb6 working on model to csharp transform
cin
parents: 4
diff changeset
166 <xsl:with-param name="scope" select="'keys'"/>
2
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
167 </xsl:call-template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
168 </xsl:template>
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
169
035de8b7b18e Temporary commit, refactoring, added readme
cin
parents:
diff changeset
170 </xsl:stylesheet>