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

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