ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
Re: RE: [xsl] Using keys to build a tree represented in XMI
by Christian Solisch other posts by this author
Dec 30 2005 8:50AM messages near this date
RE: [xsl] Using keys to build a tree represented in XMI | Re: RE: [xsl] Using keys to build a tree represented in XMI
& XSLT 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.p
articipant/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[@aggregation='aggregate']/UML:Asso
ciationEnd.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:As
sociationEnd.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@[...].fr <Florent Georges> 
To: xsl-list@[...].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@[...].com> 
--~--
Thread:
Christian Solisch
Michael Kay
Florent Georges
Christian Solisch
Christian Solisch

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved