[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: Re: RE: 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)
aggregate uml
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[@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 document4s 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 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/@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@xxxxxxxx <Florent Georges>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx

>   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 verldngert:
GMX DSL-Flatrate 1 Jahr kostenlos* http://www.gmx.net/de/go/dsl

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.