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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3221 by gerard.lemson, Sun Jan 10 14:13:41 2016 UTC revision 3222 by mdittmar, Mon Jan 11 21:00:07 2016 UTC
# Line 1  Line 1 
1  <!-- This style sheet transforms a UML model, expressed in XMI, into the basic VO-DML representation. That representation follows the schema in ./xsd/vo-dml.xsd, without the expansion fields. The document follows  <!-- This style sheet transforms a UML model, expressed in XMI, into the basic  
2    the "basic" vo-dml representation, i.e. one directly representing the UML profile's concepts. It uses the XMI-Ids for utype. Using the generate_utypes.xsl script these can be replaced with UTYPE-s according       VO-DML representation. That representation follows the schema in
3    to any desired generaiton algorithm.       ./xsd/vo-dml.xsd, without the expansion fields. The document follows
4    XSLT is tested to work on XMI generated with MagicDraw Community Edition v12.1. -->       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 [  <!DOCTYPE stylesheet [
11  <!ENTITY cr "<xsl:text>  <!ENTITY cr "<xsl:text>
12  </xsl:text>">  </xsl:text>">
# Line 297  Line 302 
302    
303    
304    
 <!--  
   <xsl:template match="*" mode="description">  
     <xsl:element name="description">  
       <xsl:choose>  
         <xsl:when test="packagedElement[@xmi:type='uml:InformationItem']">  
           <xsl:for-each select="packagedElement[@xmi:type='uml:InformationItem']">  
             &cr;<xsl:value-of select="@name" />  
           </xsl:for-each>&cr;  
         </xsl:when>  
         <xsl:otherwise>  
           TODO : Missing description : please, update your UML model asap.  
         </xsl:otherwise>  
       </xsl:choose>  
     </xsl:element>  
   </xsl:template>  
 -->  
   
   
305    <xsl:template match="*" mode="description">    <xsl:template match="*" mode="description">
306      <xsl:element name="description">      <xsl:element name="description">
307        <xsl:choose>        <xsl:choose>
# Line 554  Line 541 
541    </xsl:template>    </xsl:template>
542    
543    
544      <!-- ============================================================
545           Template: get-class-from-id
546    <!-- resolve class type for both data types (primitive or specific) and classes -->           resolve class type for both data types (primitive or specific) and classes
547             Generates 'datatype' tag.
548           ============================================================ -->
549    <xsl:template name="get-class-from-id">    <xsl:template name="get-class-from-id">
550      <xsl:param name="id" />      <xsl:param name="id" />
551  <!--      <!--
552      <xsl:variable name="c" select="key('classid',$id)" />      <xsl:variable name="c" select="key('classid',$id)" />
553   -->       -->
554      <xsl:element name="datatype">      <xsl:element name="datatype">
555      <xsl:call-template name="asElementRef">      <xsl:call-template name="asElementRef">
556      <xsl:with-param name="xmiidref" select="$id" />      <xsl:with-param name="xmiidref" select="$id" />
# Line 570  Line 559 
559    </xsl:template>    </xsl:template>
560    
561    
562      <!-- ============================================================
563           Template: get-package-from-id
564             gets name of package with provided id.
565           ============================================================ -->
566    <xsl:template name="get-package-from-id">    <xsl:template name="get-package-from-id">
567      <xsl:param name="id" />      <xsl:param name="id" />
568      <xsl:variable name="p" select="key('classid',$id)" />      <xsl:variable name="p" select="key('classid',$id)" />
# Line 579  Line 570 
570    </xsl:template>    </xsl:template>
571    
572    
573    <!-- ==================================================================================== -->    <!-- ============================================================
574    <!-- print the full path up to the specified package and append the specified suffix -->         Template: full-path                                        
575    <!-- ==================================================================================== -->           print the full path up to the specified package and      
576             append the specified suffix                              
577           ============================================================ -->
578    <xsl:template name="full-path">    <xsl:template name="full-path">
579      <xsl:param name="id" />      <xsl:param name="id" />
580      <xsl:param name="delimiter" />      <xsl:param name="delimiter" />
581      <xsl:param name="suffix" />      <xsl:param name="suffix" />
582        
583      <xsl:variable name="package" select="key('classid',$id)" />      <xsl:variable name="package" select="key('classid',$id)" />
584      <xsl:variable name="path">      <xsl:variable name="path">
585        <xsl:choose>        <xsl:choose>
# Line 598  Line 591 
591          </xsl:otherwise>          </xsl:otherwise>
592        </xsl:choose>        </xsl:choose>
593      </xsl:variable>      </xsl:variable>
594        
595      <!-- determine whether parent is a Package or not, if not, this is the root package which should be ignored. -->      <!-- determine whether parent is a Package or not. If not,
596             this is the root package which should be ignored. -->
597      <xsl:variable name="parent" select="$package/..[@xmi:type='uml:Package']" />      <xsl:variable name="parent" select="$package/..[@xmi:type='uml:Package']" />
598        
599      <xsl:choose>      <xsl:choose>
600        <xsl:when test="not($parent)">        <xsl:when test="not($parent)">
601          <xsl:value-of select="$path" />          <xsl:value-of select="$path" />
# Line 617  Line 611 
611    </xsl:template>    </xsl:template>
612    
613    
   
614    <!-- ===== tempates treating match as a ReferencableElement ==== -->    <!-- ===== tempates treating match as a ReferencableElement ==== -->
615    
616    
617      <!-- ============================================================
618           Template: aselement
619             Generate 'vodml-id' tag.
620           ============================================================ -->
621    <xsl:template match="*[@xmi:id]" mode="aselement">    <xsl:template match="*[@xmi:id]" mode="aselement">
622      <xsl:variable name="xmiid" select="@xmi:id"/>      <xsl:variable name="xmiid" select="@xmi:id"/>
 <!--  
     <xsl:variable name="vodml-id" select="/xmi:XMI/IVOA_UML_Profile:modelElement[@base_NamedElement = $xmiid]/@vodmlid" />  
  -->  
  <!-- use next iso explicit IVOA_UML_Profile prefix, as the latter must be defined explicitly, but has varying xmi:id -->  
623      <xsl:variable name="vodml-id" select="/xmi:XMI/*:modelElement[@base_NamedElement = $xmiid]/@vodmlid" />      <xsl:variable name="vodml-id" select="/xmi:XMI/*:modelElement[@base_NamedElement = $xmiid]/@vodmlid" />
   
624      <xsl:variable name="modelimport" select="/xmi:XMI/uml:Model/packagedElement[@xmi:type='uml:Model'      <xsl:variable name="modelimport" select="/xmi:XMI/uml:Model/packagedElement[@xmi:type='uml:Model'
625      and .//packagedElement[@xmi:id = $xmiid]]" />      and .//packagedElement[@xmi:id = $xmiid]]" />
626        
627        <xsl:choose>        <xsl:choose>
628          <xsl:when test="$vodml-id">          <xsl:when test="$vodml-id">
629            <xsl:element name="vodml-id">            <xsl:element name="vodml-id">
# Line 646  Line 640 
640        <xsl:element name="name">        <xsl:element name="name">
641          <xsl:value-of select="@name" />          <xsl:value-of select="@name" />
642        </xsl:element>        </xsl:element>
 <!--      <xsl:apply-templates select="." mode="description"/> -->  
643        <xsl:apply-templates select="." mode="description"/>        <xsl:apply-templates select="." mode="description"/>
644    </xsl:template>    </xsl:template>
645    
646  <!-- Generate a proper utype element. Note, an element can have a declared vodml-id, even when defined in current model -->  
647      <!-- ============================================================
648           Template: asElementRef
649             Generate a proper utype element. Note, an element can have
650             a declared vodml-id, even when defined in current model
651           ============================================================ -->
652    <xsl:template name="asElementRef">    <xsl:template name="asElementRef">
653      <xsl:param name="xmiidref"/>      <xsl:param name="xmiidref"/>
654      <xsl:if test="not($xmiidref)">      <xsl:if test="not($xmiidref)">
655      <xsl:message>asElementRef MUST be called with a non-null xmiidref</xsl:message>      <xsl:message>asElementRef MUST be called with a non-null xmiidref</xsl:message>
656      </xsl:if>      </xsl:if>
657      <!--  check whether referenced element is in a package with model import, in which case its name is the vodml-id a declared vodml-id -->      <!-- get referenced element, check for modelElement stereotype defining vodml-id  -->
658      <xsl:variable name="element" select="/xmi:XMI//*[@xmi:id = $xmiidref]"/>      <xsl:variable name="element" select="/xmi:XMI//*[@xmi:id = $xmiidref]"/>
659        <xsl:variable name="vodml-id" select="/xmi:XMI/*:modelElement[@base_NamedElement = $xmiidref]/@vodmlid" />
660        
661        <!-- get Package containing the referenced element -->
662      <xsl:variable name="package" select="/xmi:XMI//*[@xmi:id = $xmiidref]/..[@xmi:type='uml:Package']"/>      <xsl:variable name="package" select="/xmi:XMI//*[@xmi:id = $xmiidref]/..[@xmi:type='uml:Package']"/>
663        
664        <!-- get root Package containing referenced element, check for modelImport stereotype.
665             imported elements must have vodml-id resolved here. -->
666      <xsl:variable name="rootpackage" select="/xmi:XMI/uml:Model/packagedElement[@xmi:type='uml:Package' and .//*[@xmi:id = $xmiidref]]" />      <xsl:variable name="rootpackage" select="/xmi:XMI/uml:Model/packagedElement[@xmi:type='uml:Package' and .//*[@xmi:id = $xmiidref]]" />
667      <xsl:variable name="modelimport" select="/xmi:XMI/*[local-name()='modelImport' and @base_Package=$rootpackage/@xmi:id]"/>      <xsl:variable name="modelimport" select="/xmi:XMI/*[local-name()='modelImport' and @base_Package=$rootpackage/@xmi:id]"/>
668      <xsl:variable name="vodml-id" select="/xmi:XMI/*:modelElement[@base_NamedElement = $xmiidref]/@vodmlid" />      
669        <!-- report imported elements with no specified vodml-id. -->
670      <xsl:if test="$modelimport and not($vodml-id)">      <xsl:if test="$modelimport and not($vodml-id)">
671        <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>        <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>
672      </xsl:if>      </xsl:if>
673      
674        <!-- set model prefix, either current model, or imported model name -->
675      <xsl:variable name="modelprefix">      <xsl:variable name="modelprefix">
     <xsl:if test="$modelimport">  
676        <xsl:choose>        <xsl:choose>
677          <xsl:when test="$modelimport">          <xsl:when test="$modelimport">
678            <xsl:value-of select="$modelimport/@name"/>            <xsl:value-of select="$modelimport/@name"/>
# Line 677  Line 681 
681              <xsl:value-of  select="/xmi:XMI/uml:Model/@name" />              <xsl:value-of  select="/xmi:XMI/uml:Model/@name" />
682          </xsl:otherwise>          </xsl:otherwise>
683        </xsl:choose>        </xsl:choose>
       </xsl:if>  
684      </xsl:variable>      </xsl:variable>
685        
686        <!-- Generate 'vodml-ref' tag -->
687      <xsl:choose>      <xsl:choose>
688        <xsl:when test="$vodml-id">        <xsl:when test="$vodml-id">
689        <xsl:element name="vodml-ref">          <!-- with specified vodml-id -->
690          <xsl:value-of select="concat($modelprefix,':',$vodml-id)"/>          <xsl:element name="vodml-ref">
691        </xsl:element>            <xsl:value-of select="concat($modelprefix,':',$vodml-id)"/>
692            </xsl:element>
693        </xsl:when>        </xsl:when>
694        <xsl:otherwise>        <xsl:otherwise>
695            <!-- without specified vodml-id -->
696          <xsl:element name="vodml-ref">          <xsl:element name="vodml-ref">
697          <xsl:choose>          <xsl:choose>
698            <xsl:when test="$modelimport"> <!-- fall back to name if there is a modelimport -->            <xsl:when test="$modelimport">
699                    <xsl:value-of select="concat($modelprefix,':',$element/@name)"/>              <!-- imported element with no specified vodml-id, fall back to element name -->
700                <!-- eg: no modelElement stereotype assigned, or stereotype has no value. -->
701                <xsl:value-of select="concat($modelprefix,':',$element/@name)"/>
702            </xsl:when>            </xsl:when>
703            <xsl:otherwise>            <xsl:otherwise>
704            <xsl:attribute name="idref" select="$xmiidref"></xsl:attribute>              <!-- add the original xmiidref as attribute to indicate that the
705            <xsl:value-of select="$xmiidref" />                   id still must be generated -->
706                <xsl:attribute name="idref" select="$xmiidref"></xsl:attribute>
707                <xsl:value-of select="$xmiidref" />
708            </xsl:otherwise>            </xsl:otherwise>
709          </xsl:choose>          </xsl:choose>
 <!-- add the original xmiidref as attribute to indicate that utype still must be generated-->  
710          </xsl:element>          </xsl:element>
711        </xsl:otherwise>        </xsl:otherwise>
712        </xsl:choose>        </xsl:choose>
713    </xsl:template>    </xsl:template>
714    
715    
716      <!-- ============================================================
717           Template: modelimport
718             Generate 'import' tag for imported model, identified by
719             an associated modelImport stereotype.
720           ============================================================ -->
721    <xsl:template match="packagedElement[@xmi:type='uml:Package']" mode="modelimport">    <xsl:template match="packagedElement[@xmi:type='uml:Package']" mode="modelimport">
722      <xsl:variable name="xmiid" select="@xmi:id"/>      <xsl:variable name="xmiid" select="@xmi:id"/>
723      <xsl:variable name="modelimport" select="/xmi:XMI/*[local-name()='modelImport' and @base_Package = $xmiid]" />      <xsl:variable name="modelimport" select="/xmi:XMI/*[local-name()='modelImport' and @base_Package = $xmiid]" />

Legend:
Removed from v.3221  
changed lines
  Added in v.3222

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