[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: RE: [xsl] Using keys to build a tree represented in XMI
From: "Christian Solisch" <christian.solisch@xxxxxx>
Date: Fri, 30 Dec 2005 17:49:49 +0100 (MET)

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/@..." />
  <xsl:key name="class_by_id" match="UML:Class" use="@..." />
  <xsl:key name="aggregation_by_classReference" match="UML:Association"
use="UML:Association.connection/UML:AssociationEnd[@aggregation='none']/UML:AssociationEnd.participant/UML:Class/@..."
/>
  <!-- *** </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',
@...)" 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="@..." />
        </xsl:call-template>
      </xsl:variable>
      <xsl:result-document href="{concat($path,'.xml')}">
        <!-- create the document4s content, located in another stylesheet
-->
        <xsl:call-template name="create_document">
          <xsl:with-param name="class_id" select="@..."/>
        </xsl:call-template>
      </xsl:result-document>
    </xsl:for-each>
  </xsl:template>

  <!-- recursion to build a path from a leaf to the tree4s 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[@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[@aggregation='aggregate']/UML:AssociationEnd.participant/UML:Class/@..."
/>
          </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@xxxxxxxx <Florent Georges>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx

>   The 'Association.connection' doesn't have a @....  Maybe you want
> its ../@....  If I use this (see the "../"):
> 
>     <xsl:value-of
>         select="key('aggregation_by_classReference',./@...)
>                   / ../@..."/>
> 
> 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 verldngert:
GMX DSL-Flatrate 1 Jahr kostenlos* http://www.gmx.net/de/go/dsl


Current Thread
Keywords
xsl