Mercurial > pub > ModelGenerator
comparison xslt/model.xsl @ 9:d3542662cf70
working on members preprocessing
author | cin |
---|---|
date | Sun, 11 Mar 2018 10:27:32 +0300 |
parents | 5fe2e5724331 |
children | 19a8a71eaa54 |
comparison
equal
deleted
inserted
replaced
8:5fe2e5724331 | 9:d3542662cf70 |
---|---|
166 <xsl:with-param name="scope" select="'keys'"/> | 166 <xsl:with-param name="scope" select="'keys'"/> |
167 </xsl:call-template> | 167 </xsl:call-template> |
168 </xsl:template> | 168 </xsl:template> |
169 | 169 |
170 <!-- expand-member templates are used to process relations | 170 <!-- expand-member templates are used to process relations |
171 and keys and provide usefull information. This mode is designed | 171 and keys and provide useful information. This mode is designed |
172 to recursively traverse members expanding details like special | 172 to recursively traverse members expanding details like special |
173 properties generated by relations. | 173 properties generated by relations. |
174 | 174 |
175 expand-member-reference is special mode used to traverse inside | 175 expand-member-reference is special mode used to traverse inside |
176 members which are referenced from relations. By default this mode | 176 members which are referenced from relations. By default this mode |
182 @special - means that the member is a composite part and isn't | 182 @special - means that the member is a composite part and isn't |
183 accessible directly | 183 accessible directly |
184 --> | 184 --> |
185 | 185 |
186 <xsl:template match="*" mode="expand-member"> | 186 <xsl:template match="*" mode="expand-member"> |
187 <xsl:apply-templates mode="expand-member"/> | 187 <xsl:copy> |
188 </xsl:template> | 188 <xsl:copy-of select="@*"/> |
189 <xsl:template match="text()" mode="expand-member"/> | 189 <xsl:apply-templates mode="expand-member"/> |
190 | 190 </xsl:copy> |
191 <xsl:template match="*|text()" mode="expand-member-reference"/> | 191 </xsl:template> |
192 | |
192 | 193 |
193 <!-- short form of primaryKey{@name, @type} --> | 194 <!-- short form of primaryKey{@name, @type} --> |
194 <xsl:template match="m:primaryKey" mode="expand-member"> | 195 <xsl:template match="m:primaryKey" mode="expand-member"> |
196 <xsl:variable name="pkName" select="concat(@declaringType, 'Pk')"/> | |
197 <xsl:variable name="propName" select="@name" /> | |
198 | |
195 <xsl:variable name="specialProperty"> | 199 <xsl:variable name="specialProperty"> |
196 <m:property special="true"> | 200 <m:property name="{$propName}" special="true"> |
197 <xsl:copy-of select="@*" /> | 201 <xsl:copy-of select="@*[not(self::name)]" /> |
198 <m:hiddenBy name="{@name}" type="{@declaringType}"/> | 202 <m:hiddenBy name="{$pkName}" type="{@declaringType}"/> |
199 <xsl:copy-of select="*" /> | 203 <xsl:copy-of select="*" /> |
200 </m:property> | 204 </m:property> |
201 </xsl:variable> | 205 </xsl:variable> |
206 | |
202 <xsl:apply-templates select="exsl:node-set($specialProperty)" mode="expand-member"/> | 207 <xsl:apply-templates select="exsl:node-set($specialProperty)" mode="expand-member"/> |
208 <xsl:copy> | |
209 <xsl:attribute name="name"><xsl:value-of select="$pkName"/></xsl:attribute> | |
210 <m:member name="{@name}" type="{@declaringType}"/> | |
211 </xsl:copy> | |
212 </xsl:template> | |
213 | |
214 <!-- long form of primaryKey{ member{@name}+ } --> | |
215 <xsl:template match="m:primaryKey[m:member]" mode="expand-member"> | |
203 <xsl:apply-templates mode="expand-member"/> | 216 <xsl:apply-templates mode="expand-member"/> |
204 </xsl:template> | 217 </xsl:template> |
205 | 218 |
206 <!-- long form of primaryKey{ member{@name}+, property{@name, @type} } --> | 219 <!-- short form of hasA --> |
207 <xsl:template match="m:primaryKey[m:member | m:property]" mode="expand-member"> | 220 <xsl:template match="m:hasA" mode="expand-member"> |
221 <xsl:variable name="foreignPk"> | |
222 <xsl:call-template name="getPrimaryKey"> | |
223 <xsl:with-param name="type" select="@type"/> | |
224 </xsl:call-template> | |
225 </xsl:variable> | |
226 <xsl:variable name="expandedPk"> | |
227 <xsl:apply-templates select="exsl:node-set($foreignPk)" mode="expand-member"/> | |
228 </xsl:variable> | |
229 <xsl:variable name="resolvedPk"> | |
230 <xsl:apply-templates select="exsl:node-set($expandedPk)/m:primaryKey" mode="resolve-members"/> | |
231 </xsl:variable> | |
232 </xsl:template> | |
233 | |
234 <!-- short form of hasA with matched keys specified --> | |
235 <xsl:template match="m:hasA[m:thisKey]"> | |
236 <xsl:apply-templates select="m:thisKey" mode="generate-fk-properties"/> | |
237 <xsl:copy> | |
238 <xsl:copy-of select="@*"/> | |
239 <xsl:apply-templates mode="expand-member"/> | |
240 </xsl:copy> | |
241 </xsl:template> | |
242 | |
243 <xsl:template match="m:hasA/m:thisKey" mode="expand-member"> | |
244 <m:member name="{@name}" matches="{@matches}"/> | |
245 </xsl:template> | |
246 | |
247 <!-- long form of hasA --> | |
248 <xsl:template match="m:hasA[m:member]" mode="expand-member"> | |
208 <xsl:apply-templates mode="expand-member"/> | 249 <xsl:apply-templates mode="expand-member"/> |
209 </xsl:template> | 250 </xsl:template> |
210 | 251 |
211 <!-- properties declared inside relations, they are @special --> | 252 <!-- resolve expands --> |
212 <xsl:template match="m:primaryKey/m:property | m:thisKey/m:property" mode="expand-member"> | 253 |
213 <xsl:variable name="specialProperty"> | 254 <xsl:template match="m:member" mode="resolve-members"> |
214 <xsl:copy> | 255 <xsl:variable name="$name" select="@name"/> |
215 <xsl:attribute name="special">true</xsl:attribute> | 256 <xsl:variable name="$declaringType" select="@declaringType" /> |
216 <xsl:copy-of select="@*"/> | 257 |
217 <m:hiddenBy name="{@name}" type="{@declaringType}"/> | 258 <xsl:choose> |
218 <xsl:copy-of select="*"/> | 259 <xsl:when test="/*[@name=$name and @declaringType=$declaringType]"> |
219 </xsl:copy> | 260 <xsl:apply-templates select="/*[@name=$name and @declaringType=$declaringType]" mode="resolve-members"/> |
220 </xsl:variable> | 261 </xsl:when> |
221 <xsl:apply-templates select="exsl:node-set($specialProperty)" mode="expand-member"/> | 262 <xsl:otherwise> |
222 </xsl:template> | 263 <xsl:variable name="fragment"> |
223 | 264 <xsl:call-template name="getMembers"> |
224 <!-- traverse inside referenced members --> | 265 <xsl:with-param name="memberName" select="$name"/> |
225 <xsl:template match="m:member" mode="expand-member"> | 266 <xsl:with-param name="type" select="$declaringType"/> |
226 <xsl:param name="declaringType"/> | 267 </xsl:call-template> |
227 <xsl:variable name="expanded"> | 268 </xsl:variable> |
228 <xsl:call-template name="getMembers"> | 269 <xsl:apply-templates select="exsl:node-set($fragment)/*[not(@special)]" mode="resolve-members"/> |
229 <xsl:with-param name="memberName" select="@name"/> | 270 </xsl:otherwise> |
230 <xsl:with-param name="type" select="$declaringType"/> | 271 </xsl:choose> |
231 </xsl:call-template> | 272 </xsl:template> |
232 </xsl:variable> | 273 |
233 <!-- recusive expand --> | 274 <xsl:template match="m:property" mode="resolve-members"> |
234 <xsl:apply-templates select="exsl:node-set($expanded)" mode="expand-member-reference"/> | 275 <xsl:copy-of select="."/> |
235 </xsl:template> | |
236 | |
237 <xsl:template match="m:hasA/m:thisKey" mode="expand-member"> | |
238 <xsl:variable name="otherKey"> | |
239 <xsl:call-template name="getPrimaryKey"> | |
240 <xsl:with-param name="type" select="../@type"/> | |
241 </xsl:call-template> | |
242 </xsl:variable> | |
243 <xsl:variable name="otherKeyExpanded"> | |
244 <xsl:apply-templates select="exsl:node-set($otherKey)" mode="expand-member"/> | |
245 </xsl:variable> | |
246 <xsl:variable name="pk" select="exsl:node-set($otherKeyExpanded)[1]"/> | |
247 | |
248 <m:property name="{@name}" type="{$pk/@type}" hidden="true"> | |
249 <m:related name="{$pk/@name}" type="{../@type}"/> | |
250 </m:property> | |
251 </xsl:template> | |
252 | |
253 <xsl:template match="m:thisKey[m:member | property]"> | |
254 <xsl:apply-templates mode="expand-member"/> | |
255 </xsl:template> | 276 </xsl:template> |
256 | 277 |
257 </xsl:stylesheet> | 278 </xsl:stylesheet> |