/[volute]/trunk/projects/dm/vo-dml/xslt/xmi2vo-dml_Modelio_UML2.4.1.xsl
ViewVC logotype

Contents of /trunk/projects/dm/vo-dml/xslt/xmi2vo-dml_Modelio_UML2.4.1.xsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3222 - (show annotations)
Mon Jan 11 21:00:07 2016 UTC (4 years, 10 months ago) by mdittmar
File MIME type: application/xml
File size: 28780 byte(s)
merge MCD and GL from previous; fix bug in modelprefix template of xslt script; integrate updates to STC prototype
1 <!-- This style sheet transforms a UML model, expressed in XMI, into the basic
2 VO-DML representation. That representation follows the schema in
3 ./xsd/vo-dml.xsd, without the expansion fields. The document follows
4 the "basic" vo-dml representation, i.e. one directly representing the
5 UML profile's concepts. It uses the XMI-Ids for utype. Using the
6 generate_utypes.xsl script these can be replaced with UTYPE-s according
7 to any desired generaiton algorithm.
8
9 XSLT is tested to work on XMI generated with Modelio v3.0 -->
10 <!DOCTYPE stylesheet [
11 <!ENTITY cr "<xsl:text>
12 </xsl:text>">
13 ]>
14 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
15 xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
16 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17 xmlns:uml="http://www.omg.org/spec/UML/20100901"
18 xmlns:IVOA_UML_Profile='http:///schemas/IVOA_UML_Profile/_-N1WnbboEeWc7tj7hDmZiQ/0'
19 xmlns:vo-dml="http://www.ivoa.net/xml/VODML/v1.0">
20
21 <xsl:import href="common.xsl" />
22 <xsl:import href="utype.xsl" />
23
24 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
25
26 <xsl:param name="lastModified" />
27 <xsl:param name="lastModifiedText" />
28 <xsl:param name="lastModifiedXSDDatetime"/>
29
30 <!-- xml index on xml:id -->
31 <!-- problem with match="*" is that MagicDraw creates a <proxy> for Resource (for example) when it uses a stereotype and Resource shows then up twice with the same xmi:id. -->
32 <xsl:key name="classid" match="*/uml:Model//*" use="@xmi:id" />
33
34 <xsl:variable name="xmi_namespace" select="'http://schema.omg.org/spec/XMI/2.1'" />
35 <xsl:variable name="uml_namespace" select="'http://www.omg.org/spec/UML/20100901'" />
36
37 <!-- main -->
38 <xsl:template match="/">
39
40 <xsl:for-each select="xmi:XMI/IVOA_UML_Profile:modelElement">
41 <xsl:message><xsl:value-of select="@xmi:id"/></xsl:message>
42 </xsl:for-each>
43 <xsl:choose>
44 <xsl:when test="namespace-uri(/*) != $xmi_namespace">
45 <xsl:message>
46 ERROR Wrong namespace: this script only converts for <xsl:value-of select='$xmi_namespace'/>
47 Not <xsl:value-of select="namespace-uri(/*)"/>
48 </xsl:message>
49 </xsl:when>
50 <xsl:when test="not(/xmi:XMI/uml:Model)">
51 <xsl:message>
52 ERROR No uml:Model found. Possibly wrong version of uml namespace?
53 Should be
54 <xsl:value-of select="$uml_namespace" />
55 </xsl:message>
56 </xsl:when>
57 <xsl:otherwise>
58 <xsl:apply-templates select="/xmi:XMI/uml:Model" />
59 </xsl:otherwise>
60 </xsl:choose>
61 </xsl:template>
62
63
64 <!-- filters uml:Model : process only uml:Package nodes -->
65 <xsl:template match="uml:Model">
66 <xsl:comment>
67 This XML document is generated without explicit xmlns specification
68 as it complicates
69 writing XSLT scripts against it [TBD add a link to some web dicsussions
70 about it].
71 It is understood that the XML
72 schema in
73 http://volute.googlecode.com/svn/trunk/projects/theory/snapdm/specification/uml/intermediateModel.xsd
74 is to be used for validating this generated document.
75 </xsl:comment>&cr;
76 <xsl:element name="vo-dml:model">
77 <xsl:namespace name="vo-dml">http://www.ivoa.net/xml/VODML/v1.0</xsl:namespace>
78 <xsl:element name="name">
79 <xsl:value-of select="@name" />
80 </xsl:element>
81 <xsl:apply-templates select="." mode="description"/>
82
83 <xsl:apply-templates select="." mode="model.tags" />
84 <xsl:element name="lastModified">
85 <xsl:value-of select="$lastModifiedXSDDatetime" />
86 </xsl:element>
87 <xsl:apply-templates select="./*[@xmi:type='uml:Package']" mode="modelimport"/>
88 <xsl:apply-templates select="./packagedElement[@xmi:type='uml:PrimitiveType']" />
89 <xsl:apply-templates select="./packagedElement[@xmi:type='uml:Enumeration']" />
90 <xsl:apply-templates select="./packagedElement[@xmi:type='uml:DataType']"/>
91 <xsl:apply-templates select="./packagedElement[@xmi:type='uml:Class']"/>
92 <xsl:apply-templates select="./*[@xmi:type='uml:Package']"/>
93
94 </xsl:element>
95 </xsl:template>
96
97 <!-- +++++++++++++++++++++++++
98 add the model element attributes from the model stereotype
99 +++++++++++++++++++++++++ -->
100 <xsl:template match="uml:Model" mode="model.tags">
101 <xsl:variable name="xmiid" select="@xmi:id" />
102 <xsl:variable name="modeltags" select="/xmi:XMI/*[local-name()='Model' and @base_Package = $xmiid]"/>
103
104 <xsl:element name="title">
105 <xsl:value-of select="$modeltags/@title" />
106 </xsl:element>
107 <xsl:element name="author">
108 <xsl:value-of select="$modeltags/@authors" />
109 </xsl:element>
110 <xsl:element name="version">
111 <xsl:choose>
112 <xsl:when test="$modeltags/@version">
113 <xsl:value-of select="$modeltags/@version" />
114 </xsl:when>
115 <xsl:otherwise>
116 <xsl:value-of select="'0.x'" />
117 </xsl:otherwise>
118 </xsl:choose>
119 </xsl:element>
120 <xsl:if test="$modeltags/@previousVersion">
121 <xsl:element name="previousVersion">
122 <xsl:value-of select="$modeltags/@previousVersion" />
123 </xsl:element>
124 </xsl:if>
125
126 </xsl:template>
127
128
129
130 <!-- filters uml:Package : process uml:DataType, uml:Enumeration, uml:Class nodes -->
131 <xsl:template match="*[@xmi:type='uml:Package']">
132 <!-- test that the Package is not a modelimport -->
133 <xsl:variable name="xmiid" select="@xmi:id"/>
134
135
136 <xsl:choose>
137 <xsl:when test="not(/xmi:XMI/*[local-name()='modelImport' and @base_Package = $xmiid])">
138 <xsl:message>found no modelimport for package <xsl:value-of select="@name"/></xsl:message>
139
140 <!-- check if a name is defined -->
141 <xsl:if test="count(@name) > 0 and not(starts-with(@name,'_') and not(/xmi:XMI/*[local-name()='modelImport' and @base_Package = $xmiid]))">
142 <xsl:message>Generating package <xsl:value-of select="@name"/></xsl:message>
143 <!-- explicitly process only datatypes, enumeration, class -->
144 &cr;&cr;
145 <xsl:element name="package">
146 <!--
147 <xsl:attribute name="id"><xsl:value-of select="@xmi:id"></xsl:value-of></xsl:attribute>
148 -->
149 <xsl:apply-templates select="." mode="aselement" />
150 &cr;
151 <xsl:apply-templates select="./*[@xmi:type='uml:PrimitiveType']" />
152 <xsl:apply-templates select="./*[@xmi:type='uml:Enumeration']" />
153 <xsl:apply-templates select="./*[@xmi:type='uml:DataType']" />
154 <xsl:apply-templates select="./*[@xmi:type='uml:Class']" />
155
156 <xsl:apply-templates select="./*[@xmi:type='uml:Package']" />
157
158 </xsl:element>
159 &cr;&cr;
160 </xsl:if>
161 </xsl:when>
162 <xsl:otherwise>
163 <xsl:message>found modelimport for package <xsl:value-of select="@name"/>, not creating Package</xsl:message>
164 </xsl:otherwise>
165 </xsl:choose>
166 </xsl:template>
167
168
169
170 <!--
171 <xsl:template match="*[@xmi:type='uml:Dependency']">
172 <xsl:element name="depends">
173 <xsl:call-template name="asElementRef">
174 <xsl:with-param name="xmiidref" select="supplier/@xmi:idref" />
175 </xsl:call-template>
176 </xsl:element>
177 </xsl:template>
178 -->
179
180
181
182 <xsl:template match="*[@xmi:type='uml:Class']">
183 <xsl:variable name="xmiid" select="@xmi:id" />
184
185 <!-- Check whether this class is in a tree that has a contained class to do so, find first root base class, then find for it whether anay of its children is contained, if so, this class is also NOT
186 a root element -->
187 <xsl:variable name="rootid">
188 <xsl:call-template name="findRootId">
189 <xsl:with-param name="xmiid" select="$xmiid" />
190 </xsl:call-template>
191 </xsl:variable>
192
193 <xsl:variable name="isContained">
194 <xsl:apply-templates select="key('classid',$rootid)" mode="testrootelements">
195 <xsl:with-param name="count" select="'0'" />
196 </xsl:apply-templates>
197 </xsl:variable>
198
199
200
201 <xsl:element name="objectType">
202 <xsl:if test="@isAbstract">
203 <xsl:attribute name="abstract">
204 <xsl:text>true</xsl:text>
205 </xsl:attribute>
206 </xsl:if>
207
208 <xsl:apply-templates select="." mode="aselement" />
209
210 <xsl:if test="*[@xmi:type='uml:Generalization']">
211 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']" />
212 </xsl:if>
213
214 <xsl:apply-templates select="./ownedRule[@xmi:type='uml:Constraint']" />
215 <xsl:apply-templates select=".//*[@xmi:type='uml:Property']" mode="roleConstraint"/>
216
217 <!-- define "referrers" in post-processing of vo-dml.xml -->
218 <!-- <xsl:for-each select="//packagedElement/ownedAttribute[@xmi:type='uml:Property' and @association and (not(@aggregation) or @aggregation='shared') and @type = $xmiid]"> <xsl:variable name="idref"
219 select="../@xmi:id" /> <xsl:variable name="relation" select="@name" /> <xsl:element name="referrer"> <xsl:attribute name="name" select="key('classid',$idref)/@name" /> <xsl:attribute name="xmiidref" select="$idref"
220 /> <xsl:attribute name="relation" select="$relation" /> </xsl:element> </xsl:for-each> -->
221 <!-- <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and not(@association) and not(@aggregation) ]" mode="attributes" /> -->
222 <xsl:apply-templates select="ownedAttribute[@xmi:type='uml:Property' and not(@association) and not(@aggregation) ]" mode="attributes" />
223 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and @aggregation='composite']" mode="collections" />
224 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and (not(@aggregation) or @aggregation='shared')]" mode="references" />
225
226 </xsl:element>
227 &cr;&cr;
228 </xsl:template>
229
230
231
232
233 <xsl:template match="*[@xmi:type='uml:PrimitiveType']">
234 <xsl:element name="primitiveType">
235 <xsl:apply-templates select="." mode="aselement"/>
236 <xsl:if test="*[@xmi:type='uml:Generalization']">
237 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']" />
238 </xsl:if>
239 </xsl:element>
240 &cr;&cr;
241 </xsl:template>
242
243
244
245
246 <xsl:template match="*[@xmi:type='uml:DataType']">
247 <xsl:element name="dataType">
248 <xsl:if test="@isAbstract">
249 <xsl:attribute name="abstract">
250 <xsl:text>true</xsl:text>
251 </xsl:attribute>
252 </xsl:if>
253 <xsl:apply-templates select="." mode="aselement" />
254
255 <xsl:if test="*[@xmi:type='uml:Generalization']">
256 <xsl:apply-templates select="*[@xmi:type='uml:Generalization']" />
257 </xsl:if>
258 <!-- <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and not(@association)]" mode="attributes" /> -->
259 <xsl:apply-templates select="ownedAttribute[@xmi:type='uml:Property' and not(@association)]" mode="attributes" />
260 <xsl:apply-templates select=".//*[@xmi:type='uml:Property' and @association and (not(@aggregation) or @aggregation='shared')]" mode="references" />
261
262 </xsl:element>
263 &cr;&cr;
264 </xsl:template>
265
266
267
268
269 <xsl:template match="*[@xmi:type='uml:Generalization']">
270 <xsl:element name="extends">
271 <xsl:call-template name="asElementRef">
272 <xsl:with-param name="xmiidref" select="@general"/>
273 </xsl:call-template>
274 </xsl:element>
275 </xsl:template>
276
277
278
279
280 <xsl:template match="*[@xmi:type='uml:Enumeration']">
281 <xsl:element name="enumeration">
282 <xsl:apply-templates select="." mode="aselement"/>
283 <xsl:apply-templates select="*[@xmi:type='uml:EnumerationLiteral']" />
284 </xsl:element>
285 &cr;&cr;
286 </xsl:template>
287
288
289
290
291 <xsl:template match="*[@xmi:type='uml:EnumerationLiteral']">
292 <xsl:element name="literal">
293 <xsl:apply-templates select="." mode="aselement"/>
294 <!--
295 <xsl:element name="value" >
296 <xsl:value-of select="@name" />
297 </xsl:element>
298 -->
299 </xsl:element>
300 </xsl:template>
301
302
303
304
305 <xsl:template match="*" mode="description">
306 <xsl:element name="description">
307 <xsl:choose>
308 <xsl:when test="ownedComment[@xmi:type='uml:Comment']">
309 <xsl:for-each select="ownedComment[@xmi:type='uml:Comment']">
310 &cr;<xsl:value-of select="body" />
311 </xsl:for-each>&cr;
312 </xsl:when>
313 <xsl:otherwise>
314 TODO : Missing description : please, update your UML model asap.
315 </xsl:otherwise>
316 </xsl:choose>
317 </xsl:element>
318 </xsl:template>
319
320
321
322 <xsl:template match="*[@xmi:type='uml:Property']" mode="attributes">
323 <xsl:if test="not(subsettedProperty)">
324 <xsl:element name="attribute">
325 <xsl:apply-templates select="." mode="properties" />
326
327 <xsl:call-template name="attributestereotype">
328 <xsl:with-param name="xmiid" select="@xmi:id" />
329 </xsl:call-template>
330 <xsl:call-template name="semanticconceptstereotype">
331 <xsl:with-param name="xmiid" select="@xmi:id" />
332 </xsl:call-template>
333 </xsl:element>
334 </xsl:if>
335 </xsl:template>
336
337
338 <xsl:template match="*[@xmi:type='uml:Property']" mode="roleConstraint">
339 <!-- TODO test that role is constrained -->
340 <xsl:if test="subsettedProperty">
341 <xsl:element name="constraint">
342 <xsl:attribute name="xsi:type" select="'vo-dml:SubsettedRole'"/>
343 <xsl:element name="role">
344 <xsl:call-template name="asElementRef">
345 <xsl:with-param name="xmiidref" select="subsettedProperty/@xmi:idref"/>
346 </xsl:call-template>
347 </xsl:element>
348 <xsl:if test="@type">
349 <xsl:element name="datatype">
350 <xsl:call-template name="asElementRef">
351 <xsl:with-param name="xmiidref" select="@type"/>
352 </xsl:call-template>
353 </xsl:element>
354 </xsl:if>
355 <xsl:call-template name="semanticconceptstereotype">
356 <xsl:with-param name="xmiid" select="@xmi:id" />
357 </xsl:call-template>
358 </xsl:element>
359 </xsl:if>
360 </xsl:template>
361
362
363 <xsl:template match="*[@xmi:type='uml:Property']" mode="references">
364 <xsl:element name="reference">
365 <xsl:apply-templates select="." mode="properties" />
366 <xsl:if test="subsettedProperty">
367 <xsl:element name="subsets">
368 <xsl:call-template name="asElementRef">
369 <xsl:with-param name="xmiidref" select="subsettedProperty/@xmi:idref"/>
370 </xsl:call-template>
371 </xsl:element>
372 </xsl:if>
373 </xsl:element>
374 </xsl:template>
375
376
377
378
379 <xsl:template match="*[@xmi:type='uml:Property']" mode="collections">
380 <xsl:variable name="xmiid" select="@xmi:id"/>
381 <xsl:element name="collection">
382 <xsl:apply-templates select="." mode="properties" />
383 <xsl:if test="subsettedProperty">
384 <xsl:element name="subsets">
385 <xsl:call-template name="asElementRef">
386 <xsl:with-param name="xmiidref" select="subsettedProperty/@xmi:idref"/>
387 </xsl:call-template>
388 </xsl:element>
389 </xsl:if>
390 <!-- check for isOrdered -->
391 <xsl:if test="/xmi:XMI/IVOA_UML_Profile:composition[@base_Property=$xmiid]/@isOrdered">
392 <xsl:element name="isOrdered">
393 <xsl:value-of select="/xmi:XMI/IVOA_UML_Profile:composition[@base_Property=$xmiid]/@isOrdered"/>
394 </xsl:element>
395 </xsl:if>
396 </xsl:element>
397 </xsl:template>
398
399
400
401
402 <xsl:template match="ownedAttribute[@xmi:type='uml:Property']" mode="properties">
403 <xsl:apply-templates select="." mode="aselement"/>
404 <xsl:variable name="id" select="key('classid',@type)" />
405 <xsl:choose>
406 <xsl:when test="@type">
407 <xsl:call-template name="get-class-from-id">
408 <xsl:with-param name="id" select="@type" />
409 </xsl:call-template>
410 </xsl:when>
411 <xsl:otherwise>
412 <xsl:message>NO type assigned to Property '<xsl:value-of select="../@name"/>::<xsl:value-of select="@name"/>'</xsl:message>
413 </xsl:otherwise>
414 </xsl:choose>
415
416 <xsl:variable name="minOccurs">
417 <xsl:choose>
418 <xsl:when test="lowerValue"> <!-- check element exists -->
419 <xsl:choose>
420
421 <xsl:when test="lowerValue/@value"><xsl:value-of select="lowerValue/@value"/></xsl:when> <!-- check element has value field -->
422 <xsl:otherwise>0</xsl:otherwise> <!-- no value field.. default=0 -->
423 </xsl:choose>
424 </xsl:when>
425 <xsl:otherwise>1</xsl:otherwise> <!-- no lowerValue element.. default=1 -->
426 </xsl:choose>
427 </xsl:variable>
428 <xsl:variable name="maxOccurs">
429 <xsl:choose>
430 <xsl:when test="upperValue/@value">
431 <xsl:choose>
432 <xsl:when test="upperValue/@value = '*'">-1</xsl:when>
433 <xsl:otherwise><xsl:value-of select="upperValue/@value"/></xsl:otherwise>
434 </xsl:choose>
435 </xsl:when>
436 <xsl:otherwise>1</xsl:otherwise>
437 </xsl:choose>
438 </xsl:variable>
439 <xsl:element name="multiplicity">
440 <xsl:call-template name="multiplicity">
441 <xsl:with-param name="lower" select="$minOccurs" />
442 <xsl:with-param name="upper" select="$maxOccurs" />
443 </xsl:call-template>
444 </xsl:element>
445 </xsl:template>
446
447
448
449 <xsl:template name="attributestereotype">
450 <xsl:param name="xmiid" />
451 <xsl:variable name="attribute" select="/xmi:XMI/IVOA_UML_Profile:attribute[@base_Property = $xmiid]" />
452 <xsl:if test="$attribute">
453 <xsl:element name="constraints">
454 <xsl:if test="$attribute/@maxLength">
455 <xsl:element name="maxLength">
456 <xsl:value-of select="$attribute/@maxLength" />
457 </xsl:element>
458 </xsl:if>
459 <xsl:if test="$attribute/@length">
460 <xsl:element name="length">
461 <xsl:value-of select="$attribute/@length" />
462 </xsl:element>
463 </xsl:if>
464 <xsl:if test="$attribute[@uniqueGlobally = 'true']">
465 <xsl:element name="uniqueGlobally">
466 true
467 </xsl:element>
468 </xsl:if>
469 <xsl:if test="$attribute[@uniqueInCollection = 'true']">
470 <xsl:element name="uniqueInCollection">
471 true
472 </xsl:element>
473 </xsl:if>
474 </xsl:element>
475 </xsl:if>
476 </xsl:template>
477
478
479
480
481 <xsl:template name="semanticconceptstereotype">
482 <xsl:param name="xmiid" />
483 <xsl:variable name="attribute" select="/xmi:XMI/IVOA_UML_Profile:semanticconcept[@base_Property = $xmiid]" />
484 <xsl:if test="$attribute">
485 <xsl:element name="skosconcept">
486 <xsl:if test="$attribute/@topConcept">
487 <xsl:element name="topConcept">
488 <xsl:value-of select="$attribute/@topConcept" />
489 </xsl:element>
490 </xsl:if>
491 <xsl:if test="$attribute/@vocabularyURI">
492 <xsl:element name="vocabularyURI">
493 <xsl:value-of select="$attribute/@vocabularyURI" />
494 </xsl:element>
495 </xsl:if>
496 <xsl:for-each select="$attribute/vocabularyURI">
497 <xsl:element name="vocabularyURI">
498 <xsl:value-of select="." />
499 </xsl:element>
500 </xsl:for-each>
501 </xsl:element>
502 </xsl:if>
503 </xsl:template>
504
505
506
507
508
509
510 <!-- only legal values: 0..1 1 0..* 1..* If no multiplicity is defined (no upper and no lower): 0..1 -->
511
512 <xsl:template name="multiplicity">
513 <xsl:param name="lower" />
514 <xsl:param name="upper" />
515 <xsl:element name="minOccurs">
516 <xsl:choose>
517 <xsl:when test="not($lower)"> <!-- UML/XMI default is 0! -->
518 <xsl:value-of select="'0'" />
519 </xsl:when>
520 <xsl:otherwise>
521 <xsl:value-of select="$lower" />
522 </xsl:otherwise>
523 </xsl:choose>
524 </xsl:element>
525 <xsl:element name="maxOccurs">
526 <xsl:choose>
527 <xsl:when test="not($upper)">
528 <xsl:value-of select="'1'" />
529 </xsl:when>
530 <xsl:otherwise>
531 <xsl:choose>
532 <xsl:when test="$upper='*'">
533 <xsl:value-of select="'-1'" />
534 </xsl:when>
535 <xsl:otherwise>
536 <xsl:value-of select="$upper" />
537 </xsl:otherwise>
538 </xsl:choose>
539 </xsl:otherwise>
540 </xsl:choose>
541 </xsl:element>
542 </xsl:template>
543
544
545 <!-- ============================================================
546 Template: get-class-from-id
547 resolve class type for both data types (primitive or specific) and classes
548 Generates 'datatype' tag.
549 ============================================================ -->
550 <xsl:template name="get-class-from-id">
551 <xsl:param name="id" />
552 <!--
553 <xsl:variable name="c" select="key('classid',$id)" />
554 -->
555 <xsl:element name="datatype">
556 <xsl:call-template name="asElementRef">
557 <xsl:with-param name="xmiidref" select="$id" />
558 </xsl:call-template>
559 </xsl:element>
560 </xsl:template>
561
562
563 <!-- ============================================================
564 Template: get-package-from-id
565 gets name of package with provided id.
566 ============================================================ -->
567 <xsl:template name="get-package-from-id">
568 <xsl:param name="id" />
569 <xsl:variable name="p" select="key('classid',$id)" />
570 <xsl:value-of select="$p/@name" />
571 </xsl:template>
572
573
574 <!-- ============================================================
575 Template: full-path
576 print the full path up to the specified package and
577 append the specified suffix
578 ============================================================ -->
579 <xsl:template name="full-path">
580 <xsl:param name="id" />
581 <xsl:param name="delimiter" />
582 <xsl:param name="suffix" />
583
584 <xsl:variable name="package" select="key('classid',$id)" />
585 <xsl:variable name="path">
586 <xsl:choose>
587 <xsl:when test="$suffix">
588 <xsl:value-of select="concat($package/@name,$delimiter,$suffix)" />
589 </xsl:when>
590 <xsl:otherwise>
591 <xsl:value-of select="$package/@name" />
592 </xsl:otherwise>
593 </xsl:choose>
594 </xsl:variable>
595
596 <!-- determine whether parent is a Package or not. If not,
597 this is the root package which should be ignored. -->
598 <xsl:variable name="parent" select="$package/..[@xmi:type='uml:Package']" />
599
600 <xsl:choose>
601 <xsl:when test="not($parent)">
602 <xsl:value-of select="$path" />
603 </xsl:when>
604 <xsl:otherwise>
605 <xsl:call-template name="full-path">
606 <xsl:with-param name="id" select="$parent/@xmi:id" />
607 <xsl:with-param name="delimiter" select="$delimiter" />
608 <xsl:with-param name="suffix" select="$path" />
609 </xsl:call-template>
610 </xsl:otherwise>
611 </xsl:choose>
612 </xsl:template>
613
614
615 <!-- ===== tempates treating match as a ReferencableElement ==== -->
616
617
618 <!-- ============================================================
619 Template: aselement
620 Generate 'vodml-id' tag.
621 ============================================================ -->
622 <xsl:template match="*[@xmi:id]" mode="aselement">
623 <xsl:variable name="xmiid" select="@xmi:id"/>
624 <xsl:variable name="vodml-id" select="/xmi:XMI/*:modelElement[@base_NamedElement = $xmiid]/@vodmlid" />
625 <xsl:variable name="modelimport" select="/xmi:XMI/uml:Model/packagedElement[@xmi:type='uml:Model'
626 and .//packagedElement[@xmi:id = $xmiid]]" />
627
628 <xsl:choose>
629 <xsl:when test="$vodml-id">
630 <xsl:element name="vodml-id">
631 <xsl:value-of select="$vodml-id" />
632 </xsl:element>
633 </xsl:when>
634 <xsl:otherwise>
635 <xsl:element name="vodml-id">
636 <xsl:attribute name="id" select="@xmi:id"/>
637 <xsl:value-of select="$xmiid"/>
638 </xsl:element>
639 </xsl:otherwise>
640 </xsl:choose>
641 <xsl:element name="name">
642 <xsl:value-of select="@name" />
643 </xsl:element>
644 <xsl:apply-templates select="." mode="description"/>
645 </xsl:template>
646
647
648 <!-- ============================================================
649 Template: asElementRef
650 Generate a proper utype element. Note, an element can have
651 a declared vodml-id, even when defined in current model
652 ============================================================ -->
653 <xsl:template name="asElementRef">
654 <xsl:param name="xmiidref"/>
655 <xsl:if test="not($xmiidref)">
656 <xsl:message>asElementRef MUST be called with a non-null xmiidref</xsl:message>
657 </xsl:if>
658 <!-- get referenced element, check for modelElement stereotype defining vodml-id -->
659 <xsl:variable name="element" select="/xmi:XMI//*[@xmi:id = $xmiidref]"/>
660 <xsl:variable name="vodml-id" select="/xmi:XMI/*:modelElement[@base_NamedElement = $xmiidref]/@vodmlid" />
661
662 <!-- get Package containing the referenced element -->
663 <xsl:variable name="package" select="/xmi:XMI//*[@xmi:id = $xmiidref]/..[@xmi:type='uml:Package']"/>
664
665 <!-- get root Package containing referenced element, check for modelImport stereotype.
666 imported elements must have vodml-id resolved here. -->
667 <xsl:variable name="rootpackage" select="/xmi:XMI/uml:Model/packagedElement[@xmi:type='uml:Package' and .//*[@xmi:id = $xmiidref]]" />
668 <xsl:variable name="modelimport" select="/xmi:XMI/*[local-name()='modelImport' and @base_Package=$rootpackage/@xmi:id]"/>
669
670 <!-- report imported elements with no specified vodml-id. -->
671 <xsl:if test="$modelimport and not($vodml-id)">
672 <xsl:message> WARNING, vodml-ref reference <xsl:value-of select="$xmiidref"/> to element in imported model, but element has no declared vodml-id</xsl:message>
673 </xsl:if>
674
675 <!-- set model prefix, either current model, or imported model name -->
676 <xsl:variable name="modelprefix">
677 <xsl:choose>
678 <xsl:when test="$modelimport">
679 <xsl:value-of select="$modelimport/@name"/>
680 </xsl:when>
681 <xsl:otherwise>
682 <xsl:value-of select="/xmi:XMI/uml:Model/@name" />
683 </xsl:otherwise>
684 </xsl:choose>
685 </xsl:variable>
686
687 <!-- Generate 'vodml-ref' tag -->
688 <xsl:choose>
689 <xsl:when test="$vodml-id">
690 <!-- with specified vodml-id -->
691 <xsl:element name="vodml-ref">
692 <xsl:value-of select="concat($modelprefix,':',$vodml-id)"/>
693 </xsl:element>
694 </xsl:when>
695 <xsl:otherwise>
696 <!-- without specified vodml-id -->
697 <xsl:element name="vodml-ref">
698 <xsl:choose>
699 <xsl:when test="$modelimport">
700 <!-- imported element with no specified vodml-id, fall back to element name -->
701 <!-- eg: no modelElement stereotype assigned, or stereotype has no value. -->
702 <xsl:value-of select="concat($modelprefix,':',$element/@name)"/>
703 </xsl:when>
704 <xsl:otherwise>
705 <!-- add the original xmiidref as attribute to indicate that the
706 id still must be generated -->
707 <xsl:attribute name="idref" select="$xmiidref"></xsl:attribute>
708 <xsl:value-of select="$xmiidref" />
709 </xsl:otherwise>
710 </xsl:choose>
711 </xsl:element>
712 </xsl:otherwise>
713 </xsl:choose>
714 </xsl:template>
715
716
717 <!-- ============================================================
718 Template: modelimport
719 Generate 'import' tag for imported model, identified by
720 an associated modelImport stereotype.
721 ============================================================ -->
722 <xsl:template match="packagedElement[@xmi:type='uml:Package']" mode="modelimport">
723 <xsl:variable name="xmiid" select="@xmi:id"/>
724 <xsl:variable name="modelimport" select="/xmi:XMI/*[local-name()='modelImport' and @base_Package = $xmiid]" />
725 <xsl:if test="$modelimport">
726 <xsl:element name="import">
727 <xsl:variable name="vodml-id" select="@name"/>
728 <xsl:element name="name">
729 <xsl:value-of select="$vodml-id"/>
730 </xsl:element>
731 <xsl:if test="$modelimport/@ivoId">
732 <xsl:element name="ivoId"><xsl:value-of select="$modelimport/@ivoId"/>
733 </xsl:element>
734 </xsl:if>
735 <xsl:element name="url"><xsl:value-of select="$modelimport/@url"/></xsl:element>
736 <xsl:element name="documentationURL"><xsl:value-of select="$modelimport/@documentationURL"/></xsl:element>
737 </xsl:element>
738 </xsl:if>
739 </xsl:template>
740
741
742 </xsl:stylesheet>

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