/[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 655 - (show annotations)
Mon Jun 30 15:24:31 2008 UTC (12 years, 5 months ago) by gerard.lemson
File MIME type: application/xml
File size: 16390 byte(s)
Handle uniqueness constraints. 
TODO must likely handle these better, not as a tag off an <<attribute>>

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:variable name="idref" select="//ownedMember/ownedAttribute[@xmi:type='uml:Property' and @association and @aggregation='composite' and @type = $xmiid]/../@xmi:id"/>
167 <xsl:variable name="relation" select="//ownedMember/ownedAttribute[@xmi:type='uml:Property' and @association and @aggregation='composite' and @type = $xmiid]/@name"/>
168 <xsl:element name="container">
169 <xsl:attribute name="name" select="key('classid',$idref)/@name"/>
170 <xsl:attribute name="xmiidref" select="$idref"/>
171 <xsl:attribute name="relation" select="$relation"/>
172 </xsl:element>
173 </xsl:if>
174 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and not(@association)]" mode="attributes"/>
175 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and @aggregation='composite']" mode="collections"/>
176 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and (not(@aggregation) or @aggregation='shared')]" mode="references"/>
177
178 </xsl:element>
179 &cr;&cr;
180 </xsl:template>
181
182
183
184
185 <xsl:template match="*[@xmi:type='uml:PrimitiveType']">
186 <xsl:element name="primitiveType">
187 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
188 <xsl:element name="name">
189 <xsl:value-of select="@name"/>
190 </xsl:element>
191 <xsl:call-template name="description">
192 <xsl:with-param name="ownedComment" select="ownedComment"/>
193 </xsl:call-template>
194 <xsl:if test="*[@xmi:type='uml:Generalization']">
195 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']"/>
196 </xsl:if>
197 </xsl:element>
198 &cr;&cr;
199 </xsl:template>
200
201
202
203
204 <xsl:template match="*[@xmi:type='uml:DataType']">
205 <xsl:element name="dataType">
206 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
207 <xsl:if test="@isAbstract">
208 <xsl:attribute name="abstract">
209 <xsl:text>true</xsl:text>
210 </xsl:attribute>
211 </xsl:if>
212 <xsl:element name="name">
213 <xsl:value-of select="@name"/>
214 </xsl:element>
215 <xsl:call-template name="description">
216 <xsl:with-param name="ownedComment" select="ownedComment"/>
217 </xsl:call-template>
218 <xsl:if test="*[@xmi:type='uml:Generalization']">
219 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']"/>
220 </xsl:if>
221
222 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and not(@association)]" mode="attributes"/>
223
224 </xsl:element>
225 &cr;&cr;
226 </xsl:template>
227
228
229
230
231 <xsl:template match="*[@xmi:type='uml:Generalization']">
232 <xsl:variable name="c" select="key('classid',@general)"/>
233 <xsl:element name="extends">
234 <xsl:attribute name="name" select="$c/@name"/>
235 <xsl:attribute name="xmiidref" select="@general"/>
236 </xsl:element>
237 </xsl:template>
238
239
240
241
242 <xsl:template match="*[@xmi:type='uml:Enumeration']">
243 <xsl:element name="enumeration">
244 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
245 <xsl:element name="name">
246 <xsl:value-of select="@name"/>
247 </xsl:element>
248 <xsl:call-template name="description">
249 <xsl:with-param name="ownedComment" select="ownedComment"/>
250 </xsl:call-template>
251 <xsl:apply-templates select="*[@xmi:type='uml:EnumerationLiteral']"/>
252 </xsl:element>
253 &cr;&cr;
254 </xsl:template>
255
256
257
258
259 <xsl:template match="*[@xmi:type='uml:EnumerationLiteral']">
260 <xsl:element name="literal">
261 <xsl:element name="value">
262 <xsl:value-of select="@name"/>
263 </xsl:element>
264 <xsl:call-template name="description">
265 <xsl:with-param name="ownedComment" select="ownedComment"/>
266 </xsl:call-template>
267 </xsl:element>
268 </xsl:template>
269
270
271
272
273 <xsl:template name="description">
274 <xsl:param name="ownedComment"/>
275 <xsl:element name="description">
276 <xsl:choose>
277 <xsl:when test="$ownedComment/@body">
278 <xsl:value-of select="$ownedComment/@body"/>
279 </xsl:when>
280 <xsl:otherwise>TODO : Missing description : please, update your UML model asap.</xsl:otherwise>
281 </xsl:choose>
282 </xsl:element>
283 </xsl:template>
284
285
286
287
288 <xsl:template match="*[@xmi:type='uml:Property']" mode="attributes">
289 <xsl:element name="attribute">
290 <xsl:apply-templates select="." mode="properties"/>
291 <xsl:call-template name="attributestereotype">
292 <xsl:with-param name="xmiid" select="@xmi:id"/>
293 </xsl:call-template>
294 <xsl:call-template name="ontologytermstereotype">
295 <xsl:with-param name="xmiid" select="@xmi:id"/>
296 </xsl:call-template>
297 </xsl:element>
298 </xsl:template>
299
300
301
302
303 <xsl:template match="*[@xmi:type='uml:Property']" mode="references">
304 <xsl:element name="reference">
305 <xsl:apply-templates select="." mode="properties"/>
306 <xsl:if test="subsettedProperty">
307 <xsl:element name="subsets">
308 <xsl:value-of select="subsettedProperty/@xmi:idref"/>
309 </xsl:element>
310 </xsl:if>
311 </xsl:element>
312 </xsl:template>
313
314
315
316
317 <xsl:template match="*[@xmi:type='uml:Property']" mode="collections">
318 <xsl:element name="collection">
319 <xsl:apply-templates select="." mode="properties"/>
320 </xsl:element>
321 </xsl:template>
322
323
324
325
326 <xsl:template match="*[@xmi:type='uml:Property']" mode="properties">
327 <xsl:attribute name="xmiid"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
328 <xsl:variable name="id" select="key('classid',@type)"/>
329 <xsl:element name="name">
330 <xsl:value-of select="@name"/>
331 </xsl:element>
332 <xsl:call-template name="description">
333 <xsl:with-param name="ownedComment" select="ownedComment"/>
334 </xsl:call-template>
335 <xsl:call-template name="get-class-from-id">
336 <xsl:with-param name="id" select="@type"/>
337 </xsl:call-template>
338 <xsl:element name="multiplicity">
339 <xsl:call-template name="multiplicity">
340 <xsl:with-param name="lower" select="lowerValue/@value"/>
341 <xsl:with-param name="upper" select="upperValue/@value"/>
342 </xsl:call-template>
343 </xsl:element>
344 </xsl:template>
345
346
347
348 <xsl:template name="attributestereotype">
349 <xsl:param name="xmiid"/>
350 <xsl:variable name="attribute" select="/xmi:XMI/IVOA_Profile_Def2:attribute[@base_Property = $xmiid]"/>
351 <xsl:if test="$attribute">
352 <xsl:element name="constraints">
353 <xsl:if test="$attribute/@maxLength">
354 <xsl:element name="maxLength"><xsl:value-of select="$attribute/@maxLength"/></xsl:element>
355 </xsl:if>
356 <xsl:if test="$attribute[@uniqueGlobally = 'true']">
357 <xsl:element name="uniqueGlobally">true</xsl:element>
358 </xsl:if>
359 <xsl:if test="$attribute[@uniqueInCollection = 'true']">
360 <xsl:element name="uniqueInCollection">true</xsl:element>
361 </xsl:if>
362 </xsl:element>
363 </xsl:if>
364 </xsl:template>
365
366
367
368
369 <xsl:template name="ontologytermstereotype">
370 <xsl:param name="xmiid"/>
371 <xsl:variable name="attribute" select="/xmi:XMI/IVOA_Profile_Def2:ontologyterm[@base_Property = $xmiid]"/>
372 <xsl:if test="$attribute">
373 <xsl:element name="ontologyterm">
374 <xsl:if test="$attribute/@ontologyURI">
375 <xsl:element name="ontologyURI"><xsl:value-of select="$attribute/@ontologyURI"/></xsl:element>
376 </xsl:if>
377 </xsl:element>
378 </xsl:if>
379 </xsl:template>
380
381
382
383 <!--
384 only legal values: 0..1 1 0..* 1..*
385
386 If no multiplicity is defined (no upper and no lower): 0..1
387 -->
388
389 <xsl:template name="multiplicity">
390 <xsl:param name="lower"/>
391 <xsl:param name="upper"/>
392 <xsl:choose>
393 <xsl:when test="not($lower) and (not($upper) or $upper = 1)">
394 <xsl:value-of select="'0..1'"/>
395 </xsl:when>
396 <xsl:when test="$upper = 1 and $lower = 1">
397 <xsl:value-of select="'1'"/>
398 </xsl:when>
399 <xsl:when test="$upper = -1 and not($lower)">
400 <xsl:value-of select="'0..*'"/>
401 </xsl:when>
402 <xsl:when test="$upper = -1 and $lower = 1">
403 <xsl:value-of select="'1..*'"/>
404 </xsl:when>
405 </xsl:choose>
406 </xsl:template>
407
408
409
410
411 <!-- resolve class type for both data types (primitive or specific) and classes -->
412 <xsl:template name="get-class-from-id">
413 <xsl:param name="id"/>
414 <xsl:variable name="c" select="key('classid',$id)"/>
415 <xsl:element name="datatype">
416 <xsl:attribute name="name" select="$c/@name"/>
417 <xsl:attribute name="xmiidref" select="$id"/>
418 </xsl:element>
419 </xsl:template>
420
421
422
423
424 <xsl:template name="get-package-from-id">
425 <xsl:param name="id"/>
426 <xsl:variable name="p" select="key('classid',$id)"/>
427 <xsl:value-of select="$p/@name"/>
428 </xsl:template>
429
430
431 <!-- ==================================================================================== -->
432 <!-- print the full path up to the specified package and append the specified suffix -->
433 <!-- ==================================================================================== -->
434 <xsl:template name="full-path">
435 <xsl:param name="id"/>
436 <xsl:param name="delimiter"/>
437 <xsl:param name="suffix"/>
438
439 <xsl:variable name="package" select="key('classid',$id)"/>
440 <xsl:variable name="path">
441 <xsl:choose>
442 <xsl:when test="$suffix">
443 <xsl:value-of select="concat($package/@name,$delimiter,$suffix)"/>
444 </xsl:when>
445 <xsl:otherwise>
446 <xsl:value-of select="$package/@name"/>
447 </xsl:otherwise>
448 </xsl:choose>
449 </xsl:variable>
450
451 <!-- determine whether parent is a Package or not, if not, this is the root package which should be ignored. -->
452 <xsl:variable name="parent" select="$package/..[@xmi:type='uml:Package']"/>
453
454 <xsl:choose>
455 <xsl:when test="not($parent)">
456 <xsl:value-of select="$path"/>
457 </xsl:when>
458 <xsl:otherwise>
459 <xsl:call-template name="full-path">
460 <xsl:with-param name="id" select="$parent/@xmi:id"/>
461 <xsl:with-param name="delimiter" select="$delimiter"/>
462 <xsl:with-param name="suffix" select="$path"/>
463 </xsl:call-template>
464 </xsl:otherwise>
465 </xsl:choose>
466 </xsl:template>
467
468
469 </xsl:stylesheet>

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