xsl-list
[Top] [All Lists]

Re: RE: Using keys to build a tree represented in XMI

2005-12-30 09:49:49
Hi drkm,

thank you for your reply! You are right, I chose the wrong attribute. 

After restructuring the xsl file I am able to follow the aggregations in the
XMI-file by recursion. If someone is interested, the working file follows.
Any hints on best practices regarding modularity or structure will be
appreciated!

<?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"
exclude-result-prefixes="UML">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
  
  <!-- *** <Keys> ************************************************ -->
  <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" match="UML:Association"
use="UML:Association.connection/UML:AssociationEnd[(_at_)aggregation='none']/UML:AssociationEnd.participant/UML:Class/@xmi.idref"
/>
  <!-- *** </Keys> *********************************************** -->

  
  <xsl:template match="/">
    <!-- apply templates on all stereotypes "dokument" -->
    <xsl:apply-templates select="key('stereotype_by_name', 'dokument')"
mode="compute_fileName" />
  </xsl:template>

  <!-- expects one and only one node -->
  <xsl:template match="UML:Stereotype" mode="compute_fileName">
    <!-- apply templates on all classes of this stereotype -->
    <xsl:apply-templates select="key('class_by_stereotypeReference',
@xmi.id)" mode="compute_fileName" />
  </xsl:template>

  <xsl:template match="UML:Class" mode="compute_fileName">
    <xsl:for-each select=".">
      <xsl:variable name="path">
        <xsl:call-template name="compute_path">
          <xsl:with-param name="class_id" select="@xmi.id" />
        </xsl:call-template>
      </xsl:variable>
      <xsl:result-document href="{concat($path,'.xml')}">
        <!-- create the document´s content, located in another stylesheet
-->
        <xsl:call-template name="create_document">
          <xsl:with-param name="class_id" select="@xmi.id"/>
        </xsl:call-template>
      </xsl:result-document>
    </xsl:for-each>
  </xsl:template>

  <!-- recursion to build a path from a leaf to the tree´s root (in the UML
model, by following the aggregations) -->
  <xsl:template name="compute_path">
    <xsl:param name="class_id" />
    <xsl:variable name="temp"
select="key('aggregation_by_classReference',$class_id)" />
    <xsl:choose>
      <!-- inverse Termination Condition -->
      <!-- if the root is not reached, e.g. an aggregation leads to another
class -->
      <xsl:when
test="$temp/UML:Association.connection/UML:AssociationEnd[(_at_)aggregation='aggregate']/UML:AssociationEnd.participant/UML:Class">
        <!-- Recursive Descent -->
        <!-- then call the recursion again with the connected class_id -->
        <xsl:variable name="recursive_result">
          <xsl:call-template name="compute_path">
            <xsl:with-param name="class_id"
select="$temp/UML:Association.connection/UML:AssociationEnd[(_at_)aggregation='aggregate']/UML:AssociationEnd.participant/UML:Class/@xmi.idref"
/>
          </xsl:call-template>
        </xsl:variable>
        <!-- Recursive Ascent -->
        <xsl:value-of
select="concat($recursive_result,'/',key('class_by_id',$class_id)/@name)" />
      </xsl:when>
      <!-- Termination Condition -->
      <xsl:otherwise>
        <!-- root class is reached, so terminate the descent -->
        <xsl:value-of select="key('class_by_id',$class_id)/@name" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>



----- Original Message -----
From: darkman_spam(_at_)yahoo(_dot_)fr <Florent Georges>
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com

  The 'Association.connection' doesn't have a @xmi.id.  Maybe you want
its ../@xmi.id.  If I use this (see the "../"):

    <xsl:value-of
        select="key('aggregation_by_classReference',./@xmi.id)
                  / ../@xmi.id"/>

Saxon output (with the text output method):

    Aggregation_id_1

  Is it the expected behaviour?

--drkm


-- 


DSL-Aktion wegen großer Nachfrage bis 28.2.2006 verlängert:
GMX DSL-Flatrate 1 Jahr kostenlos* http://www.gmx.net/de/go/dsl

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>