/[volute]/trunk/projects/theory/snapdm/res/xmi2intermediate.xsl
ViewVC logotype

Contents of /trunk/projects/theory/snapdm/res/xmi2intermediate.xsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 219 - (show annotations)
Tue Apr 15 06:23:24 2008 UTC (12 years, 7 months ago) by gerard.lemson
File MIME type: application/xml
File size: 13201 byte(s)
Committing resources dealing with generation of intermediate and DDLs.
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3 This style sheet transforms a UML model, expressed ain XMI, into an
4 "intermediate" XMl representation.
5 That representation follows the schema in intermediateModel.xsd.
6
7 -->
8 <!DOCTYPE stylesheet [
9 <!ENTITY cr "<xsl:text>
10 </xsl:text>">
11 ]>
12 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
13 xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
14 xmlns:uml="http://schema.omg.org/spec/UML/2.0">
15
16
17 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
18
19 <xsl:param name="xmlLastModified"/>
20 <xsl:param name="xslLastModified"/>
21
22 <!-- xml index on xml:id -->
23 <xsl:key name="classid" match="*" use="@xmi:id"/>
24
25 <xsl:variable name="dmmd_namespace" select="'http://ivoa.org/theory/datamodel/generationmetadata/v0.1'"/>
26 <xsl:variable name="xmi_namespace" select="'http://schema.omg.org/spec/XMI/2.1'"/>
27 <xsl:variable name="uml_namespace" select="'http://schema.omg.org/spec/UML/2.0'"/>
28
29 <xsl:variable name="lastModified">
30 <xsl:choose>
31 <xsl:when test="number(/uml:Model/lastModifiedDate) > number($xslLastModified)"><xsl:value-of select="/uml:Model/lastModifiedDate"/></xsl:when>
32 <xsl:otherwise><xsl:value-of select="$xslLastModified"/></xsl:otherwise>
33 </xsl:choose>
34 </xsl:variable>
35
36
37
38
39 <!-- main -->
40 <xsl:template match="/">
41 <xsl:choose>
42 <xsl:when test="namespace-uri(/*) != 'http://schema.omg.org/spec/XMI/2.1'">
43 <ERROR>Wrong namespace: this script can convert only XMI v2.1</ERROR>
44 </xsl:when>
45 <xsl:otherwise>
46 <xsl:apply-templates select="*/uml:Model" />
47 </xsl:otherwise>
48 </xsl:choose>
49 </xsl:template>
50
51
52
53
54 <!-- filters uml:Model : process only uml:Package nodes -->
55 <xsl:template match="uml:Model">
56 <xsl:element name="model">
57 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
58 <xsl:element name="name"><xsl:value-of select="@name"/></xsl:element>
59 <xsl:element name="lastModifiedDate"><xsl:value-of select="$lastModified"/></xsl:element>
60 <xsl:element name="description"><xsl:value-of select="./ownedComment/@body"/></xsl:element>
61 <xsl:apply-templates select="./*[@xmi:type='uml:PrimitiveType']">
62 <xsl:sort select="@name"/>
63 </xsl:apply-templates>
64 <xsl:apply-templates select="./*[@xmi:type='uml:Package']"/>
65 </xsl:element>
66 </xsl:template>
67
68
69
70
71 <!-- filters uml:Package : process uml:DataType, uml:Enumeration, uml:Class nodes -->
72 <xsl:template match="*[@xmi:type='uml:Package']">
73
74 <!-- check if a name is defined -->
75 <xsl:if test="count(@name) > 0">
76 <!-- explicitly process only datatypes, enumeration, class -->
77 &cr;&cr;
78 <xsl:element name="package">
79 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
80 <xsl:element name="name">
81 <xsl:value-of select="@name"/>
82 </xsl:element>
83 <xsl:apply-templates select="ownedComment"/>
84 &cr;
85
86 <xsl:if test="count(./*[@xmi:type='uml:Dependency']) > 0">
87 &cr;
88 <xsl:comment> Dependencies </xsl:comment>&cr;&cr;
89
90 <xsl:apply-templates select="./*[@xmi:type='uml:Dependency']"/>
91 </xsl:if>
92 <xsl:if test="count(./*[@xmi:type='uml:DataType']) > 0">
93 &cr;
94 <xsl:comment> Data types </xsl:comment>&cr;&cr;
95
96 <xsl:apply-templates select="./*[@xmi:type='uml:DataType']" />
97 </xsl:if>
98
99 <xsl:if test="count(./*[@xmi:type='uml:Enumeration']) > 0">
100 &cr;
101 <xsl:comment> Enumerations </xsl:comment>&cr;&cr;
102
103 <xsl:apply-templates select="./*[@xmi:type='uml:Enumeration']" />
104 </xsl:if>
105
106 <xsl:if test="count(./*[@xmi:type='uml:Class']) > 0">
107 &cr;
108 <xsl:comment> Classes </xsl:comment>&cr;&cr;
109
110 <xsl:apply-templates select="./*[@xmi:type='uml:Class']" />
111 </xsl:if>
112
113 <xsl:apply-templates select="./*[@xmi:type='uml:Package']"/>
114
115 </xsl:element>
116 &cr;&cr;
117 </xsl:if>
118 </xsl:template>
119
120
121 <xsl:template match="*[@xmi:type='uml:Dependency']">
122 <xsl:element name="depends">
123 <xsl:attribute name="xmiidref"><xsl:value-of select="supplier/@xmi:idref"/></xsl:attribute>
124 </xsl:element>
125 </xsl:template>
126
127
128
129
130 <xsl:template match="*[@xmi:type='uml:Class']">
131 <xsl:element name="objectType">
132 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
133 <xsl:if test="@isAbstract">
134 <xsl:attribute name="abstract">
135 <xsl:text>true</xsl:text>
136 </xsl:attribute>
137 </xsl:if>
138 <xsl:element name="name">
139 <xsl:value-of select="@name"/>
140 </xsl:element>
141 <xsl:apply-templates select="ownedComment"/>
142 <xsl:if test="*[@xmi:type='uml:Generalization']">
143 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']"/>
144 </xsl:if>
145
146 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and not(@association)]" mode="attributes"/>
147 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and @aggregation='composite']" mode="collections"/>
148 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and (not(@aggregation) or @aggregation='shared')]" mode="references"/>
149
150 </xsl:element>
151 &cr;&cr;
152 </xsl:template>
153
154
155
156
157 <xsl:template match="*[@xmi:type='uml:DataType']">
158 <xsl:element name="dataType">
159 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
160 <xsl:if test="@isAbstract">
161 <xsl:attribute name="abstract">
162 <xsl:text>true</xsl:text>
163 </xsl:attribute>
164 </xsl:if>
165 <xsl:element name="name">
166 <xsl:value-of select="@name"/>
167 </xsl:element>
168 <xsl:apply-templates select="ownedComment"/>
169 <xsl:if test="*[@xmi:type='uml:Generalization']">
170 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']"/>
171 </xsl:if>
172
173 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and not(@association)]" mode="attributes"/>
174
175 </xsl:element>
176 &cr;&cr;
177 </xsl:template>
178
179
180
181
182 <xsl:template match="*[@xmi:type='uml:Generalization']">
183 <xsl:element name="extends">
184 <xsl:call-template name="get-class-from-id">
185 <xsl:with-param name="id">
186 <xsl:value-of select="@general"/>
187 </xsl:with-param>
188 </xsl:call-template>
189 </xsl:element>
190 </xsl:template>
191
192
193
194
195 <xsl:template match="*[@xmi:type='uml:Enumeration']">
196 <xsl:element name="enumeration">
197 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
198 <xsl:element name="name">
199 <xsl:value-of select="@name"/>
200 </xsl:element>
201 <xsl:apply-templates select="ownedComment"/>
202 <xsl:apply-templates select="*[@xmi:type='uml:EnumerationLiteral']"/>
203 </xsl:element>
204 &cr;&cr;
205 </xsl:template>
206
207
208
209
210 <xsl:template match="*[@xmi:type='uml:EnumerationLiteral']">
211 <xsl:element name="literal">
212 <xsl:element name="value">
213 <xsl:value-of select="@name"/>
214 </xsl:element>
215 <xsl:apply-templates select="ownedComment"/>
216 </xsl:element>
217 </xsl:template>
218
219
220
221
222 <xsl:template match="ownedComment">
223 <xsl:element name="description">
224 <xsl:value-of select="@body"/>
225 </xsl:element>
226 </xsl:template>
227
228
229
230
231 <xsl:template match="*[@xmi:type='uml:Property']" mode="attributes">
232 <xsl:element name="attribute">
233 <xsl:apply-templates select="." mode="properties"/>
234 </xsl:element>
235 </xsl:template>
236
237
238
239
240 <xsl:template match="*[@xmi:type='uml:Property']" mode="references">
241 <xsl:element name="reference">
242 <xsl:apply-templates select="." mode="properties"/>
243 <xsl:if test="subsettedProperty">
244 <xsl:element name="subsets">
245 <xsl:value-of select="subsettedProperty/@xmi:idref"/>
246 </xsl:element>
247 </xsl:if>
248 </xsl:element>
249 </xsl:template>
250
251
252
253
254 <xsl:template match="*[@xmi:type='uml:Property']" mode="collections">
255 <xsl:element name="collection">
256 <xsl:apply-templates select="." mode="properties"/>
257 </xsl:element>
258 </xsl:template>
259
260
261
262
263 <xsl:template match="*[@xmi:type='uml:Property']" mode="properties">
264 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
265 <xsl:variable name="id" select="key('classid',@type)"/>
266 <xsl:element name="name">
267 <xsl:value-of select="@name"/>
268 </xsl:element>
269 <xsl:apply-templates select="ownedComment"/>
270 <xsl:call-template name="get-class-from-id">
271 <xsl:with-param name="id">
272 <xsl:value-of select="@type"/>
273 </xsl:with-param>
274 </xsl:call-template>
275 <xsl:element name="multiplicity">
276 <xsl:call-template name="multiplicity">
277 <xsl:with-param name="lower" select="lowerValue/@value"/>
278 <xsl:with-param name="upper" select="upperValue/@value"/>
279 </xsl:call-template>
280 </xsl:element>
281 </xsl:template>
282
283
284
285
286 <xsl:template name="multiplicity">
287 <xsl:param name="lower"/>
288 <xsl:param name="upper"/>
289 <xsl:variable name="u">
290 <xsl:choose>
291 <xsl:when test="not($upper)">
292 <xsl:value-of select="'1'"/>
293 </xsl:when>
294 <xsl:when test="$upper = -1">
295 <xsl:value-of select="'*'"/>
296 </xsl:when>
297 <xsl:otherwise>
298 <xsl:value-of select="$upper"/>
299 </xsl:otherwise>
300 </xsl:choose>
301 </xsl:variable>
302 <xsl:variable name="l">
303 <xsl:choose>
304 <xsl:when test="not($lower)">
305 <xsl:choose>
306 <xsl:when test="not($upper)">
307 <xsl:value-of select="'0'"/>
308 </xsl:when>
309 <xsl:otherwise>
310 <xsl:value-of select="$u"/>
311 </xsl:otherwise>
312 </xsl:choose>
313 </xsl:when>
314 <xsl:otherwise>
315 <xsl:value-of select="$lower"/>
316 </xsl:otherwise>
317 </xsl:choose>
318 </xsl:variable>
319 <xsl:choose>
320 <xsl:when test="$l = $u">
321 <xsl:value-of select="$l"/>
322 </xsl:when>
323 <xsl:otherwise>
324 <xsl:value-of select="$l"/>..<xsl:value-of select="$u"/>
325 </xsl:otherwise>
326 </xsl:choose>
327 </xsl:template>
328
329
330
331
332 <!-- resolve class type for both data types (primitive or specific) and classes -->
333 <xsl:template name="get-class-from-id">
334 <xsl:param name="id"/>
335 <xsl:variable name="c" select="key('classid',$id)"/>
336 <xsl:element name="datatype">
337 <xsl:attribute name="xmiidref"><xsl:value-of select="$id"></xsl:value-of></xsl:attribute>
338 <xsl:choose>
339 <xsl:when test="$c/@xmi:type = 'uml:PrimitiveType'">
340 <xsl:attribute name="type">
341 <xsl:value-of select="$c/@name"/>
342 </xsl:attribute>
343 </xsl:when>
344 <xsl:otherwise>
345 <xsl:attribute name="package">
346 <xsl:call-template name="full-path">
347 <xsl:with-param name="id">
348 <xsl:value-of select="$c/../@xmi:id"/>
349 </xsl:with-param>
350 <xsl:with-param name="delimiter">
351 <xsl:value-of select="'.'"/>
352 </xsl:with-param>
353
354 </xsl:call-template>
355 </xsl:attribute>
356 <xsl:attribute name="class">
357 <xsl:value-of select="$c/@name"/>
358 </xsl:attribute>
359 </xsl:otherwise>
360 </xsl:choose>
361 </xsl:element>
362 </xsl:template>
363
364
365
366
367 <!-- ==================================================================================== -->
368 <!-- print the full path up to the specified package and append the specified suffix -->
369 <!-- ==================================================================================== -->
370 <xsl:template name="full-path">
371 <xsl:param name="id"/>
372 <xsl:param name="delimiter"/>
373 <xsl:param name="suffix"/>
374
375 <xsl:variable name="package" select="key('classid',$id)"/>
376 <xsl:variable name="path">
377 <xsl:choose>
378 <xsl:when test="$suffix">
379 <xsl:value-of select="concat($package/@name,$delimiter,$suffix)"/>
380 </xsl:when>
381 <xsl:otherwise>
382 <xsl:value-of select="$package/@name"/>
383 </xsl:otherwise>
384 </xsl:choose>
385 </xsl:variable>
386
387 <!-- determine whether parent is a Package or not, if not, this is the root package which should be ignored. -->
388 <xsl:variable name="parent" select="$package/..[@xmi:type='uml:Package']"/>
389
390 <xsl:choose>
391 <xsl:when test="not($parent)">
392 <xsl:value-of select="$path"/>
393 </xsl:when>
394 <xsl:otherwise>
395 <xsl:call-template name="full-path">
396 <xsl:with-param name="id" select="$parent/@xmi:id"/>
397 <xsl:with-param name="delimiter" select="$delimiter"/>
398 <xsl:with-param name="suffix" select="$path"/>
399 </xsl:call-template>
400 </xsl:otherwise>
401 </xsl:choose>
402 </xsl:template>
403
404
405 </xsl:stylesheet>

msdemlei@ari.uni-heidelberg.de
ViewVC Help
Powered by ViewVC 1.1.26