/[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 343 - (show annotations)
Wed Apr 30 16:30:47 2008 UTC (12 years, 7 months ago) by gerard.lemson
File MIME type: application/xml
File size: 15651 byte(s)
only generate joined form ..2ddl. added ..2ddl_hierarchical if at some point we want to generate according to that strategy.
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:xsi="http://www.w3.org/2001/XMLSchema-instance"
15 xmlns:uml="http://schema.omg.org/spec/UML/2.0"
16 xmlns:IVOA_Profile_Def2='http://www.magicdraw.com/schemas/IVOA_Profile_Def2.xmi'>
17
18
19 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
20
21 <xsl:param name="lastModified"/>
22
23 <!-- xml index on xml:id -->
24 <xsl:key name="classid" match="*" use="@xmi:id"/>
25
26 <xsl:variable name="dmmd_namespace" select="'http://ivoa.org/theory/datamodel/generationmetadata/v0.1'"/>
27 <xsl:variable name="xmi_namespace" select="'http://schema.omg.org/spec/XMI/2.1'"/>
28 <xsl:variable name="uml_namespace" select="'http://schema.omg.org/spec/UML/2.0'"/>
29
30
31
32
33 <!-- main -->
34 <xsl:template match="/">
35 <xsl:choose>
36 <xsl:when test="namespace-uri(/*) != 'http://schema.omg.org/spec/XMI/2.1'">
37 <ERROR>Wrong namespace: this script can convert only XMI v2.1</ERROR>
38 </xsl:when>
39 <xsl:otherwise>
40 <xsl:apply-templates select="*/uml:Model" />
41 </xsl:otherwise>
42 </xsl:choose>
43 </xsl:template>
44
45
46
47
48 <!-- filters uml:Model : process only uml:Package nodes -->
49 <xsl:template match="uml:Model">
50 <xsl:comment>This XML document is generated without explicit xmlns specification as it complicates
51 writing XSLT scripts against it [TBD add a link to some web dicsussions about it].
52 It is understood that the XML schema in
53 http://volute.googlecode.com/svn/trunk/projects/theory/snapdm/input/intermediateModel.xsd
54 is to be used for validating this generated document.</xsl:comment>&cr;
55 <xsl:element name="model">
56 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
57 <xsl:element name="name"><xsl:value-of select="@name"/></xsl:element>
58 <xsl:call-template name="description">
59 <xsl:with-param name="ownedComment" select="./ownedComment"/>
60 </xsl:call-template>
61 <xsl:element name="lastModifiedDate"><xsl:value-of select="$lastModified"/></xsl:element>
62 <xsl:apply-templates select="." mode="authors"/>
63 <xsl:apply-templates select="./*[@xmi:type='uml:Package']"/>
64 </xsl:element>
65 </xsl:template>
66
67
68
69
70 <xsl:template match="uml:Model" mode="authors">
71
72 </xsl:template>
73
74
75
76
77 <!-- filters uml:Package : process uml:DataType, uml:Enumeration, uml:Class nodes -->
78 <xsl:template match="*[@xmi:type='uml:Package']">
79
80 <!-- check if a name is defined -->
81 <xsl:if test="count(@name) > 0">
82 <!-- explicitly process only datatypes, enumeration, class -->
83 &cr;&cr;
84 <xsl:element name="package">
85 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
86 <xsl:element name="name">
87 <xsl:value-of select="@name"/>
88 </xsl:element>
89 <xsl:call-template name="description">
90 <xsl:with-param name="ownedComment" select="ownedComment"/>
91 </xsl:call-template>
92 &cr;
93
94 <xsl:if test="count(./*[@xmi:type='uml:Dependency']) > 0">
95 &cr;
96 <xsl:comment> Dependencies </xsl:comment>&cr;&cr;
97
98 <xsl:apply-templates select="./*[@xmi:type='uml:Dependency']"/>
99 </xsl:if>
100 <xsl:if test="count(./*[@xmi:type='uml:Class']) > 0">
101 &cr;
102 <xsl:comment> Classes </xsl:comment>&cr;&cr;
103
104 <xsl:apply-templates select="./*[@xmi:type='uml:Class']" />
105 </xsl:if>
106
107 <xsl:if test="count(./*[@xmi:type='uml:DataType']) > 0">
108 &cr;
109 <xsl:comment> Data types </xsl:comment>&cr;&cr;
110
111 <xsl:apply-templates select="./*[@xmi:type='uml:DataType']" />
112 </xsl:if>
113
114 <xsl:if test="count(./*[@xmi:type='uml:Enumeration']) > 0">
115 &cr;
116 <xsl:comment> Enumerations </xsl:comment>&cr;&cr;
117
118 <xsl:apply-templates select="./*[@xmi:type='uml:Enumeration']" />
119 </xsl:if>
120
121 <xsl:if test="count(./*[@xmi:type='uml:PrimitiveType']) > 0">
122 &cr;
123 <xsl:comment> Primitive Types </xsl:comment>&cr;&cr;
124
125 <xsl:apply-templates select="./*[@xmi:type='uml:PrimitiveType']" />
126 </xsl:if>
127
128 <xsl:apply-templates select="./*[@xmi:type='uml:Package']"/>
129
130 </xsl:element>
131 &cr;&cr;
132 </xsl:if>
133 </xsl:template>
134
135
136
137
138 <xsl:template match="*[@xmi:type='uml:Dependency']">
139 <xsl:element name="depends">
140 <xsl:attribute name="xmiidref"><xsl:value-of select="supplier/@xmi:idref"/></xsl:attribute>
141 </xsl:element>
142 </xsl:template>
143
144
145
146
147 <xsl:template match="*[@xmi:type='uml:Class']">
148 <xsl:variable name="xmiid" select="@xmi:id"/>
149 <xsl:element name="objectType">
150 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
151 <xsl:if test="@isAbstract">
152 <xsl:attribute name="abstract">
153 <xsl:text>true</xsl:text>
154 </xsl:attribute>
155 </xsl:if>
156 <xsl:element name="name">
157 <xsl:value-of select="@name"/>
158 </xsl:element>
159 <xsl:call-template name="description">
160 <xsl:with-param name="ownedComment" select="ownedComment"/>
161 </xsl:call-template>
162 <xsl:if test="*[@xmi:type='uml:Generalization']">
163 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']"/>
164 </xsl:if>
165 <xsl:if test="//ownedMember/ownedAttribute[@xmi:type='uml:Property' and @association and @aggregation='composite' and @type = $xmiid]">
166 <xsl:element name="container"><xsl:value-of select="//ownedMember/ownedAttribute[@xmi:type='uml:Property' and @association and @aggregation='composite' and @type = $xmiid]/../@xmi:id"/></xsl:element>
167 </xsl:if>
168 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and not(@association)]" mode="attributes"/>
169 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and @aggregation='composite']" mode="collections"/>
170 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and (not(@aggregation) or @aggregation='shared')]" mode="references"/>
171
172 </xsl:element>
173 &cr;&cr;
174 </xsl:template>
175
176
177
178
179 <xsl:template match="*[@xmi:type='uml:PrimitiveType']">
180 <xsl:element name="primitiveType">
181 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
182 <xsl:element name="name">
183 <xsl:value-of select="@name"/>
184 </xsl:element>
185 <xsl:call-template name="description">
186 <xsl:with-param name="ownedComment" select="ownedComment"/>
187 </xsl:call-template>
188 <xsl:if test="*[@xmi:type='uml:Generalization']">
189 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']"/>
190 </xsl:if>
191 </xsl:element>
192 &cr;&cr;
193 </xsl:template>
194
195
196
197
198 <xsl:template match="*[@xmi:type='uml:DataType']">
199 <xsl:element name="dataType">
200 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
201 <xsl:if test="@isAbstract">
202 <xsl:attribute name="abstract">
203 <xsl:text>true</xsl:text>
204 </xsl:attribute>
205 </xsl:if>
206 <xsl:element name="name">
207 <xsl:value-of select="@name"/>
208 </xsl:element>
209 <xsl:call-template name="description">
210 <xsl:with-param name="ownedComment" select="ownedComment"/>
211 </xsl:call-template>
212 <xsl:if test="*[@xmi:type='uml:Generalization']">
213 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']"/>
214 </xsl:if>
215
216 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and not(@association)]" mode="attributes"/>
217
218 </xsl:element>
219 &cr;&cr;
220 </xsl:template>
221
222
223
224
225 <xsl:template match="*[@xmi:type='uml:Generalization']">
226 <xsl:element name="extends">
227 <xsl:call-template name="get-class-from-id">
228 <xsl:with-param name="id" select="@general"/>
229 </xsl:call-template>
230 </xsl:element>
231 </xsl:template>
232
233
234
235
236 <xsl:template match="*[@xmi:type='uml:Enumeration']">
237 <xsl:element name="enumeration">
238 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
239 <xsl:element name="name">
240 <xsl:value-of select="@name"/>
241 </xsl:element>
242 <xsl:call-template name="description">
243 <xsl:with-param name="ownedComment" select="ownedComment"/>
244 </xsl:call-template>
245 <xsl:apply-templates select="*[@xmi:type='uml:EnumerationLiteral']"/>
246 </xsl:element>
247 &cr;&cr;
248 </xsl:template>
249
250
251
252
253 <xsl:template match="*[@xmi:type='uml:EnumerationLiteral']">
254 <xsl:element name="literal">
255 <xsl:element name="value">
256 <xsl:value-of select="@name"/>
257 </xsl:element>
258 <xsl:call-template name="description">
259 <xsl:with-param name="ownedComment" select="ownedComment"/>
260 </xsl:call-template>
261 </xsl:element>
262 </xsl:template>
263
264
265
266
267 <xsl:template name="description">
268 <xsl:param name="ownedComment"/>
269 <xsl:element name="description">
270 <xsl:choose>
271 <xsl:when test="$ownedComment/@body">
272 <xsl:value-of select="$ownedComment/@body"/>
273 </xsl:when>
274 <xsl:otherwise>TODO : Missing description : please, update your UML model asap.</xsl:otherwise>
275 </xsl:choose>
276 </xsl:element>
277 </xsl:template>
278
279
280
281
282 <xsl:template match="*[@xmi:type='uml:Property']" mode="attributes">
283 <xsl:element name="attribute">
284 <xsl:apply-templates select="." mode="properties"/>
285 <xsl:call-template name="attributestereotype">
286 <xsl:with-param name="xmiid" select="@xmi:id"/>
287 </xsl:call-template>
288 </xsl:element>
289 </xsl:template>
290
291
292
293
294 <xsl:template match="*[@xmi:type='uml:Property']" mode="references">
295 <xsl:element name="reference">
296 <xsl:apply-templates select="." mode="properties"/>
297 <xsl:if test="subsettedProperty">
298 <xsl:element name="subsets">
299 <xsl:value-of select="subsettedProperty/@xmi:idref"/>
300 </xsl:element>
301 </xsl:if>
302 </xsl:element>
303 </xsl:template>
304
305
306
307
308 <xsl:template match="*[@xmi:type='uml:Property']" mode="collections">
309 <xsl:element name="collection">
310 <xsl:apply-templates select="." mode="properties"/>
311 </xsl:element>
312 </xsl:template>
313
314
315
316
317 <xsl:template match="*[@xmi:type='uml:Property']" mode="properties">
318 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
319 <xsl:variable name="id" select="key('classid',@type)"/>
320 <xsl:element name="name">
321 <xsl:value-of select="@name"/>
322 </xsl:element>
323 <xsl:call-template name="description">
324 <xsl:with-param name="ownedComment" select="ownedComment"/>
325 </xsl:call-template>
326 <xsl:call-template name="get-class-from-id">
327 <xsl:with-param name="id" select="@type"/>
328 </xsl:call-template>
329 <xsl:element name="multiplicity">
330 <xsl:call-template name="multiplicity">
331 <xsl:with-param name="lower" select="lowerValue/@value"/>
332 <xsl:with-param name="upper" select="upperValue/@value"/>
333 </xsl:call-template>
334 </xsl:element>
335 </xsl:template>
336
337
338
339 <xsl:template name="attributestereotype">
340 <xsl:param name="xmiid"/>
341 <xsl:variable name="attribute" select="/xmi:XMI/IVOA_Profile_Def2:attribute[@base_Property = $xmiid]"/>
342 <xsl:if test="$attribute">
343 <xsl:element name="constraints">
344 <xsl:if test="$attribute/@maxLength">
345 <xsl:element name="maxLength"><xsl:value-of select="$attribute/@maxLength"/></xsl:element>
346 </xsl:if>
347 </xsl:element>
348 </xsl:if>
349 </xsl:template>
350
351
352 <!--
353 only legal values: 0..1 1 0..* 1..*
354
355 If no multiplicity is defined (no upper and no lower): 0..1
356 -->
357
358 <xsl:template name="multiplicity">
359 <xsl:param name="lower"/>
360 <xsl:param name="upper"/>
361 <xsl:choose>
362 <xsl:when test="not($lower) and (not($upper) or $upper = 1)">
363 <xsl:value-of select="'0..1'"/>
364 </xsl:when>
365 <xsl:when test="$upper = 1 and $lower = 1">
366 <xsl:value-of select="'1'"/>
367 </xsl:when>
368 <xsl:when test="$upper = -1 and not($lower)">
369 <xsl:value-of select="'0..*'"/>
370 </xsl:when>
371 <xsl:when test="$upper = -1 and $lower = 1">
372 <xsl:value-of select="'1..*'"/>
373 </xsl:when>
374 </xsl:choose>
375 </xsl:template>
376
377
378
379
380 <!-- resolve class type for both data types (primitive or specific) and classes -->
381 <xsl:template name="get-class-from-id">
382 <xsl:param name="id"/>
383 <xsl:variable name="c" select="key('classid',$id)"/>
384 <xsl:element name="datatype">
385 <xsl:attribute name="xmiidref"><xsl:value-of select="$id"></xsl:value-of></xsl:attribute>
386 <xsl:choose>
387 <xsl:when test="$c/@xmi:type = 'uml:PrimitiveType'">
388 <xsl:attribute name="type">
389 <xsl:value-of select="$c/@name"/>
390 </xsl:attribute>
391 </xsl:when>
392 <xsl:otherwise>
393 <xsl:attribute name="package">
394 <xsl:call-template name="full-path">
395 <xsl:with-param name="id" select="$c/../@xmi:id"/>
396 <xsl:with-param name="delimiter" select="'.'"/>
397 </xsl:call-template>
398 </xsl:attribute>
399 <xsl:attribute name="class">
400 <xsl:value-of select="$c/@name"/>
401 </xsl:attribute>
402 </xsl:otherwise>
403 </xsl:choose>
404 </xsl:element>
405 </xsl:template>
406
407
408
409
410 <xsl:template name="get-package-from-id">
411 <xsl:param name="id"/>
412 <xsl:variable name="p" select="key('classid',$id)"/>
413 <xsl:value-of select="$p/@name"/>
414 </xsl:template>
415
416
417 <!-- ==================================================================================== -->
418 <!-- print the full path up to the specified package and append the specified suffix -->
419 <!-- ==================================================================================== -->
420 <xsl:template name="full-path">
421 <xsl:param name="id"/>
422 <xsl:param name="delimiter"/>
423 <xsl:param name="suffix"/>
424
425 <xsl:variable name="package" select="key('classid',$id)"/>
426 <xsl:variable name="path">
427 <xsl:choose>
428 <xsl:when test="$suffix">
429 <xsl:value-of select="concat($package/@name,$delimiter,$suffix)"/>
430 </xsl:when>
431 <xsl:otherwise>
432 <xsl:value-of select="$package/@name"/>
433 </xsl:otherwise>
434 </xsl:choose>
435 </xsl:variable>
436
437 <!-- determine whether parent is a Package or not, if not, this is the root package which should be ignored. -->
438 <xsl:variable name="parent" select="$package/..[@xmi:type='uml:Package']"/>
439
440 <xsl:choose>
441 <xsl:when test="not($parent)">
442 <xsl:value-of select="$path"/>
443 </xsl:when>
444 <xsl:otherwise>
445 <xsl:call-template name="full-path">
446 <xsl:with-param name="id" select="$parent/@xmi:id"/>
447 <xsl:with-param name="delimiter" select="$delimiter"/>
448 <xsl:with-param name="suffix" select="$path"/>
449 </xsl:call-template>
450 </xsl:otherwise>
451 </xsl:choose>
452 </xsl:template>
453
454
455 </xsl:stylesheet>

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