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

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="";
version="2.0" xmlns:UML="org.omg.xmi.namespace.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="" />
  <xsl:key name="aggregation_by_classReference" match="UML:Association"
  <!-- *** </Keys> *********************************************** -->

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

  <!-- 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 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: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=""/>

  <!-- 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)" />
      <!-- inverse Termination Condition -->
      <!-- if the root is not reached, e.g. an aggregation leads to another
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"
        <!-- Recursive Ascent -->
select="concat($recursive_result,'/',key('class_by_id',$class_id)/@name)" />
      <!-- Termination Condition -->
        <!-- root class is reached, so terminate the descent -->
        <xsl:value-of select="key('class_by_id',$class_id)/@name" />


----- 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*

Current Thread