/[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 230 - (show annotations)
Wed Apr 16 06:39:25 2008 UTC (12 years, 7 months ago) by gerard.lemson
File MIME type: application/xml
File size: 14006 byte(s)


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

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