home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 February / PCpro_2005_02.ISO / files / opensource / Dia_0.94 / dia-setup-0.94.exe / dia-uml.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-08-20  |  9.9 KB  |  249 lines

  1. <?xml version="1.0"?>
  2. <!-- 
  3.      Transform dia UML objects to a convenient structure
  4.      
  5.      Copyright(c) 2002 Matthieu Sozeau <mattam@netcourrier.com>     
  6.  
  7.      This program is free software; you can redistribute it and/or modify
  8.      it under the terms of the GNU General Public License as published by
  9.      the Free Software Foundation; either version 2 of the License, or
  10.      (at your option) any later version.
  11.      
  12.      This program is distributed in the hope that it will be useful,
  13.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.      GNU General Public License for more details.
  16.      
  17.      You should have received a copy of the GNU General Public License
  18.      along with this program; if not, write to the Free Software
  19.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20.  
  21. -->
  22.  
  23. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  24.   xmlns:dia="http://www.lysator.liu.se/~alla/dia/"
  25.   version="1.0">
  26.   <xsl:output method="xml" indent="yes"/>
  27.  
  28.   <xsl:template match="/">
  29.     <xsl:element name="dia-uml">
  30.       <xsl:choose>
  31.         <xsl:when test="*/*/*/dia:object[@type='UML - LargePackage']">
  32.           <xsl:apply-templates select="*/*/*/dia:object[@type='UML - LargePackage']"/>      
  33.         </xsl:when>
  34.         <xsl:otherwise>
  35.           <xsl:apply-templates/>
  36.         </xsl:otherwise>
  37.       </xsl:choose>
  38.     </xsl:element>
  39.   </xsl:template>
  40.  
  41.   <xsl:template match="dia:object[@type='UML - LargePackage']">
  42.     <xsl:element name="package">
  43.       <xsl:element name="name">
  44.  
  45.         <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='name']/dia:string, '#'), '#')"/>
  46.       </xsl:element>
  47.       <xsl:apply-templates select="../dia:object[@type='UML - Class']"/>      
  48.     </xsl:element>
  49.   </xsl:template>
  50.  
  51.   <xsl:template match="dia:object[@type='UML - Class']">
  52.     <xsl:element name="class">
  53.       <xsl:attribute name="name">
  54.         <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='name']/dia:string, '#'), '#')"/>            
  55.       </xsl:attribute>
  56.       <xsl:if test="dia:attribute[@name='stereotype']">
  57.         <xsl:attribute name="stereotype">
  58.           <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='stereotype']/dia:string, '#'), '#')"/>                
  59.         </xsl:attribute>
  60.       </xsl:if>
  61.       <xsl:if test="dia:attribute[@name='abstract']/dia:boolean/@val='true'">
  62.         <xsl:attribute name="abstract">1</xsl:attribute>
  63.       </xsl:if>
  64.       <xsl:element name="comment">
  65.     <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='comment']/dia:string, '#'), '#')"/>
  66.       </xsl:element>
  67.       <xsl:element name="attributes">
  68.         <xsl:apply-templates select="dia:attribute[@name='attributes']"/>
  69.       </xsl:element>
  70.       <xsl:element name="operations">
  71.         <xsl:apply-templates select="dia:attribute[@name='operations']"/>
  72.       </xsl:element>
  73.     </xsl:element>    
  74.   </xsl:template>
  75.  
  76.  
  77.   <xsl:template match="dia:composite[@type='umlattribute']">
  78.     <xsl:element name="attribute">
  79.       <xsl:if test="dia:attribute[@name='class_scope']/dia:boolean/@val='true'">
  80.         <xsl:attribute name="class_scope">1</xsl:attribute>
  81.       </xsl:if>
  82.       <xsl:choose>
  83.         <xsl:when test="dia:attribute[@name='visibility']/dia:enum/@val=1">
  84.           <xsl:attribute name="visibility">private</xsl:attribute>
  85.         </xsl:when>
  86.         <xsl:when test="dia:attribute[@name='visibility']/dia:enum/@val=2">
  87.           <xsl:attribute name="visibility">protected</xsl:attribute>
  88.         </xsl:when>
  89.         <xsl:when test="dia:attribute[@name='visibility']/dia:enum/@val=0">
  90.           <xsl:attribute name="visibility">public</xsl:attribute>
  91.         </xsl:when>
  92.       </xsl:choose>
  93.  
  94.       <xsl:element name="type">
  95.         <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='type']/dia:string, '#'), '#')"/>
  96.       </xsl:element>
  97.  
  98.       <xsl:element name="name">
  99.         <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='name']/dia:string, '#'), '#')"/>
  100.       </xsl:element>
  101.  
  102.       <xsl:element name="comment">
  103.     <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='comment']/dia:string, '#'), '#')"/>
  104.       </xsl:element>
  105.  
  106.       <xsl:if test="not(dia:attribute[@name='value']/dia:string='##')">
  107.         <xsl:element name="value">
  108.           <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='value']/dia:string, '#'), '#')"/>
  109.         </xsl:element>
  110.       </xsl:if>
  111.     </xsl:element>
  112.   </xsl:template>
  113.   
  114.   
  115.   <xsl:template match="dia:composite[@type='umloperation']">
  116.     <xsl:element name="operation">
  117.       <xsl:choose>
  118.         <xsl:when test="dia:attribute[@name='inheritance_type']/dia:enum/@val=2">
  119.           <xsl:attribute name="inheritance">leaf</xsl:attribute>
  120.         </xsl:when>
  121.         <xsl:when test="dia:attribute[@name='inheritance_type']/dia:enum/@val=1">
  122.           <xsl:attribute name="inheritance">polymorphic</xsl:attribute>
  123.         </xsl:when>
  124.         <xsl:when test="dia:attribute[@name='inheritance_type']/dia:enum/@val=0">
  125.           <xsl:attribute name="inheritance">abstract</xsl:attribute>
  126.         </xsl:when>
  127.       </xsl:choose>
  128.       <xsl:choose>
  129.         <xsl:when test="dia:attribute[@name='visibility']/dia:enum/@val=1">
  130.           <xsl:attribute name="visibility">private</xsl:attribute>
  131.         </xsl:when>
  132.         <xsl:when test="dia:attribute[@name='visibility']/dia:enum/@val=2">
  133.           <xsl:attribute name="visibility">protected</xsl:attribute>
  134.         </xsl:when>
  135.         <xsl:when test="dia:attribute[@name='visibility']/dia:enum/@val=0">
  136.           <xsl:attribute name="visibility">public</xsl:attribute>
  137.         </xsl:when>
  138.       </xsl:choose>
  139.       
  140.       <xsl:if test="dia:attribute[@name='class_scope']/dia:boolean/@val='true'">
  141.         <xsl:attribute name="class_scope">1</xsl:attribute>
  142.       </xsl:if>
  143.  
  144.       <xsl:choose>
  145.         <xsl:when test="dia:attribute[@name='query']/dia:boolean/@val='true'">
  146.           <xsl:attribute name="query">1</xsl:attribute>
  147.         </xsl:when>
  148.         <xsl:otherwise>
  149.           <xsl:attribute name="query">0</xsl:attribute>
  150.         </xsl:otherwise>
  151.       </xsl:choose>
  152.       
  153.       <xsl:if test="not(dia:attribute[@name='type']/dia:string='##')">
  154.         <xsl:element name="type">
  155.           <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='type']/dia:string, '#'), '#')"/>
  156.         </xsl:element>
  157.       </xsl:if>    
  158.       
  159.       <xsl:element name="name">
  160.         <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='name']/dia:string, '#'), '#')"/>
  161.       </xsl:element>
  162.  
  163.       <xsl:if test="not(dia:attribute[@name='comment']/dia:string='##')">
  164.     <xsl:element name="comment">
  165.       <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='comment']/dia:string, '#'), '#')"/>
  166.     </xsl:element>
  167.       </xsl:if>
  168.       
  169.       <xsl:if test="dia:attribute[@name='parameters']/dia:composite[@type='umlparameter']">
  170.     <xsl:element name="parameters">
  171.       <xsl:for-each select="dia:attribute[@name='parameters']/dia:composite[@type='umlparameter']">
  172.         <xsl:element name="parameter">
  173.           <xsl:choose>
  174.         <xsl:when test="dia:attribute[@name='kind']/dia:enum/@val=1">
  175.           <xsl:attribute name="kind">in</xsl:attribute>
  176.         </xsl:when>
  177.         <xsl:when test="dia:attribute[@name='kind']/dia:enum/@val=2">
  178.           <xsl:attribute name="kind">out</xsl:attribute>
  179.         </xsl:when>
  180.         <xsl:when test="dia:attribute[@name='kind']/dia:enum/@val=3">
  181.           <xsl:attribute name="kind">inout</xsl:attribute>
  182.         </xsl:when>
  183.           </xsl:choose>
  184.           
  185.           <xsl:element name="type">
  186.         <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='type']/dia:string, '#'), '#')"/>
  187.           </xsl:element>
  188.           
  189.           <xsl:element name="name">
  190.         <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='name']/dia:string, '#'), '#')"/>
  191.           </xsl:element>
  192.           
  193.           <xsl:if test="dia:attribute[@name='comment']">
  194.         <xsl:element name="comment">
  195.           <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='comment']/dia:string, '#'), '#')"/>
  196.         </xsl:element>
  197.           </xsl:if>
  198.           
  199.           <xsl:if test="not(dia:attribute[@name='value']/dia:string='##')">
  200.         <xsl:element name="value">
  201.           <xsl:value-of select="substring-before(substring-after(dia:attribute[@name='value']/dia:string, '#'), '#')"/>
  202.         </xsl:element>              
  203.           </xsl:if>
  204.           
  205.         </xsl:element>
  206.       </xsl:for-each>      
  207.     </xsl:element>
  208.       </xsl:if>
  209.     </xsl:element>
  210.   </xsl:template>
  211.  
  212.   <xsl:template match="*/*/dia:object[@type='UML - Component']">
  213.     <xsl:element name="component">
  214.       <xsl:if test="not(dia:attribute[@name='stereotype']/dia:string='##')">
  215.     <xsl:attribute name="stereotype"><xsl:value-of 
  216.       select="substring-before(substring-after(dia:attribute[@name='stereotype']/dia:string, '#'), '#')"/></xsl:attribute>              
  217.       </xsl:if>
  218.       <xsl:if test="not(dia:attribute[@name='text']/dia:composite/dia:attribute/dia:string='##')"><xsl:value-of 
  219.     select="substring-before(substring-after(dia:attribute[@name='text']/dia:composite/dia:attribute/dia:string, '#'), '#')"/>              
  220.       </xsl:if>
  221.     </xsl:element>
  222.   </xsl:template>
  223.   
  224.   <xsl:template match="text()"></xsl:template>
  225.  
  226.   <xsl:template match="node()|@*">
  227.     <xsl:apply-templates match="node()|@*"/>  
  228.   </xsl:template>
  229. </xsl:stylesheet>
  230.  
  231.  
  232. <!-- Keep this comment at the end of the file
  233. Local variables:
  234. mode: xml
  235. sgml-omittag:nil
  236. sgml-shorttag:nil
  237. sgml-namecase-general:nil
  238. sgml-general-insert-case:lower
  239. sgml-minimize-attributes:nil
  240. sgml-always-quote-attributes:t
  241. sgml-indent-step:2
  242. sgml-indent-data:t
  243. sgml-parent-document:nil
  244. sgml-exposed-tags:nil
  245. sgml-local-catalogs:nil
  246. sgml-local-ecat-files:nil
  247. End:
  248. -->
  249.