[xsl] Using keys to build a tree represented in XMI

Subject: [xsl] Using keys to build a tree represented in XMI
From: "Christian Solisch" <christian.solisch@xxxxxx>
Date: Wed, 28 Dec 2005 19:32:04 +0100 (MET)
Hi community,

I am new to XSLT and actually trying to use it for a transformation of a XMI
file. After two weeks of trying I really don4t know how to proceed. I am not
sure, if XSLT is really what I need to get the job done. Any help (or hint
to use anything else ;-) will be really appreciated!

I use Saxon 8.6.1 on XSLT 2.0

In an UML tool (enterprise architect) I modelled a tree-structure consisting
of classes. They are stereotyped by <<node>> and <<leaf>> and connected by
aggregations. After exporting it to XMI I like to generate the path for each
leaf (leading from root to leaf).

After digging out that an aggregation points to both connected classes and
each class references its stereotype, I tried to use keys to resolve the
references. The aggregation4s direction can be seen in the "aggregation"
attribute of each of the two end points ("none" -> "aggregate"). But after
identifying the leaf classes I don4t manage it to follow the aggregation...

Here is my stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0" xmlns:UML="org.omg.xmi.namespace.UML"

<!-- *** <Keys> ************************************************ -->
<xsl:key name="package_by_name" match="UML:Package" use="@name" />
<xsl:key name="stereotype_by_name" match="UML:Stereotype" use="@name" />
<xsl:key name="class_by_stereotypeReference" match="UML:Class"
use="UML:ModelElement.stereotype/UML:Stereotype/@xmi.idref" />
<xsl:key name="class_by_ID" match="UML:Class" use="@xmi.id" />
<xsl:key name="aggregation_by_classReference"
<!-- *** </Keys> *********************************************** -->

<xsl:template match="/">
<xsl:apply-templates select="key('stereotype_by_name', 'leaf')" />

<xsl:template match="UML:Stereotype">
<xsl:apply-templates select="key('class_by_stereotypeReference', @xmi.id)"/>

<!-- now i should have only leaf classes -->
<xsl:template match="UML:Class">
  <xsl:for-each select="." >
  <!-- here i have to find the aggregation -->
  <!-- pointing to this class, actually not working -->
A part of the XMI file looks like this:

 <UML:Model name="Views" xmi.id="Model_id_1">
   <UML:Stereotype xmi.id="Stereotype_id_1" name="node" ></UML:Stereotype>
   <UML:Stereotype xmi.id="Stereotype_id_2" name="leaf" ></UML:Stereotype>
   <UML:Package name="Package_Tree" xmi.id="Package_id_1">

     <UML:Class name="Node_1" xmi.id="Node_id_1">
       <UML:Stereotype xmi.idref="Stereotype_id_1"/>

     <UML:Association xmi.id="Aggregation_id_1">

       <UML:AssociationEnd aggregation="none">
         <UML:Class xmi.idref="Node_id_2"/>

       <UML:AssociationEnd aggregation="aggregate">
         <UML:Class xmi.idref="Node_id_1"/>


     <UML:Class name="Node_2" xmi.id="Node_id_2">
       <UML:Stereotype xmi.idref="Stereotype_id_2"/>

    </UML:Namespace.ownedElement>						   </UML:Package>

So if somebody could help me with some ideas how to follow the connection
between my nodes, I would be very happy!

Thanks in advance

Telefonieren Sie schon oder sparen Sie noch?
NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie

Current Thread