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-uml2dhtml.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-10  |  12.2 KB  |  312 lines

  1. <xsl:stylesheet
  2.  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.  version="1.0"
  4.  xmlns="http://www.w3.org/1999/xhtml" xmlns:dia="http://www.lysator.liu.se/~alla/dia">
  5. <!-- converts data from (uncompressed) dia UML file to an HTML file -->
  6. <!-- requires an XLST processor -->
  7.   <xsl:template
  8.    match="/dia:diagram">
  9.     <html>
  10.       <head>
  11.         <title>UML</title>
  12.  
  13. <style type="text/css">
  14.             .header {color: black; font-family: Arial, helvetica,
  15. sans-serif;}
  16.             .headerhighlight { color: red; font-family: Arial,
  17. Helvetica, san-serif;}
  18.             .details {font-family: Arial, Helvetica, sans-serif;
  19. background-color: white; color: black;}
  20.             .datatype {font-family: Courier; color: #555555; }
  21.             .description {font-family: Courier; color: black;
  22. margin-left: 5pt;}
  23.  
  24. </style>
  25.  
  26. <script language="JavaScript1.2" src="ua.js"></script>
  27.  
  28. <script type="text/javascript"
  29.  language="JavaScript1.2">
  30.  
  31. function toggleHighlight(block, id) {
  32.   if(navigator.family=="ie4") {
  33.     var theElement = block.children[0];
  34.      theElement.className = theElement.className=="headerhighlight"?"header":"headerhighlight";
  35.  
  36.   }
  37.   if(navigator.family=="gecko") {
  38.     document.getElementById(id).firstChild.className = document.getElementById(id).firstChild.className=="headerhighlight"?"header":"headerhighlight";
  39.   }
  40. };
  41.  
  42. function toggleVisibility(block, id) {
  43.  if((navigator.family=="gecko")||((navigator.family="ie4"))) {
  44.   var childNodes = document.getElementById(id).childNodes;
  45.   if(navigator.family=="gecko") {
  46.     var start=2;
  47.   }
  48.   else {
  49.     var start=1;
  50.   }
  51.   for(var i=start; i!= childNodes.length; i++) {
  52.     if(!childNodes.item(i).style) {
  53.       }
  54.     else {
  55.       childNodes.item(i).style.display = childNodes.item(i).style.display=='none'?'block':'none';
  56.     }
  57.   }
  58.  }
  59. };
  60.  
  61. </script>
  62.       </head>
  63.  
  64.       <body
  65.        text="#000000"
  66.        bgcolor="#FFFFFF"
  67.        link="#FF0000"
  68.        alink="#FF0000"
  69.        vlink="#FF0000">
  70.         <h1
  71.          class="header">UML</h1>
  72.  
  73.         <xsl:for-each
  74.          select="dia:layer">
  75. <xsl:if test="./@name!='Legend'">
  76. <xsl:for-each select="dia:object">
  77. <xsl:sort select="dia:attribute/dia:string/text()" lang="en" data-type="text"/>
  78.           <xsl:if
  79.            test="./@type='UML - Class'">
  80.             <xsl:element name="div">
  81. <xsl:attribute name="class">header</xsl:attribute>
  82. <xsl:attribute name="onmouseover">toggleHighlight(this,'<xsl:value-of select="@id"/>')</xsl:attribute>
  83. <xsl:attribute name="onmouseout">toggleHighlight(this,'<xsl:value-of select="@id"/>')</xsl:attribute>
  84. <xsl:attribute name="onclick">toggleVisibility(this,'<xsl:value-of select="@id"/>')</xsl:attribute>
  85. <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
  86.               <xsl:for-each
  87.                select="dia:attribute">
  88.                 <xsl:if
  89.                  test="./@name='name'">
  90. <h2>
  91.                   <xsl:element
  92.                    name="a">
  93.                     <xsl:attribute
  94.                      name="name">
  95.                       <xsl:value-of
  96.                        select="../@id" />
  97.                     </xsl:attribute>
  98.  
  99.                       <xsl:value-of
  100.                        select="substring(dia:string/text(),2, string-length(dia:string/text())-2)" />
  101.  
  102.                   </xsl:element>
  103. </h2>
  104.                 </xsl:if>
  105.  
  106.                 <xsl:if
  107.                  test="./@name='attributes'">
  108.                   <xsl:variable
  109.                    name="classid"
  110.                    select="../@id" />
  111.  
  112.                   <xsl:for-each
  113.                    select="../../dia:object">
  114.                     <xsl:if
  115.                      test="./@type='UML - Generalization'">
  116.                       <xsl:if
  117.                        test="dia:connections/dia:connection[2]/@to = $classid">
  118.  
  119.                         <xsl:variable
  120.                          name="parentid"
  121.                          select="dia:connections/dia:connection[1]/@to" />
  122.  
  123.                         <xsl:for-each
  124.                          select="../dia:object">
  125.                           <xsl:if
  126.                            test="./@type='UML - Class'">
  127.                             <xsl:if
  128.                              test="./@id = $parentid">
  129.                               <div
  130.                                style="display='none'">Inherits from
  131.  
  132.                               <xsl:for-each
  133.                                select="dia:attribute">
  134.                                 <xsl:if
  135.                                  test="./@name='name'">
  136.                                   <xsl:element
  137.                                    name="a">
  138.                                     <xsl:attribute
  139.                                      name="href">#<xsl:value-of
  140.                                      select="$parentid" />
  141.                                     </xsl:attribute><xsl:value-of
  142.                                      select="substring(dia:string/text(),2,string-length(dia:string/text())-2)" />
  143.                                   </xsl:element>
  144.                                 </xsl:if>
  145.                               </xsl:for-each>
  146.                               </div>
  147.                             </xsl:if>
  148.                           </xsl:if>
  149.                         </xsl:for-each>
  150.                       </xsl:if>
  151.                     </xsl:if>
  152.  
  153.                     <xsl:if
  154.                      test="./@type='UML - Generalization'">
  155.                       <xsl:if
  156.                        test="dia:connections/dia:connection[1]/@to = $classid">
  157.  
  158.                         <xsl:variable
  159.                          name="childid"
  160.                          select="dia:connections/dia:connection[2]/@to" />
  161.  
  162.                         <xsl:for-each
  163.                          select="../dia:object">
  164.                           <xsl:if
  165.                            test="./@type='UML - Class'">
  166.                             <xsl:if
  167.                              test="./@id = $childid">
  168.                               <div
  169.                                style="display='none'">Inherited by
  170.                               <xsl:for-each
  171.                                select="dia:attribute">
  172.  
  173.                                 <xsl:if
  174.                                  test="./@name='name'">
  175.                                   <xsl:element
  176.                                    name="a">
  177.                                     <xsl:attribute
  178.                                      name="href">#<xsl:value-of
  179.                                      select="$childid" />
  180.                                     </xsl:attribute><xsl:value-of
  181.                                      select="substring(dia:string/text(),2,string-length(dia:string/text())-2)" />
  182.                                   </xsl:element>
  183.                                 </xsl:if>
  184.                               </xsl:for-each>
  185.                               </div>
  186.                             </xsl:if>
  187.                           </xsl:if>
  188.                         </xsl:for-each>
  189.                       </xsl:if>
  190.                     </xsl:if>
  191.                  
  192.  
  193.    <xsl:if test="./@type='UML - Realizes'">
  194.                       <xsl:if test="dia:connections/dia:connection[1]/@to = $classid">
  195.                         <xsl:variable
  196.                          name="childid"
  197.                          select="dia:connections/dia:connection[2]/@to" />
  198.  
  199.                         <xsl:for-each
  200.                          select="../dia:object">
  201.                           <xsl:if
  202.                            test="./@type='UML - Object'">
  203.                             <xsl:if
  204.                              test="./@id = $childid">
  205.                   
  206.  
  207.                 <xsl:for-each select="dia:attribute">
  208.                   <xsl:if test="./@name='exstate'">
  209.                                 <xsl:choose>
  210.                       <xsl:when test="dia:string/text()='#private#'"></xsl:when>
  211.                                   <xsl:otherwise>
  212.                                       <div style="display='none'">Subtype 
  213.                                         <xsl:for-each
  214.                                              select="../dia:attribute/dia:composite/dia:attribute">
  215.                                           <xsl:if
  216.                                                test="./@name='string'">
  217.                                             <xsl:if test="dia:string/text()!='##'">
  218.                                               <b><xsl:value-of
  219.                                                       select="substring(dia:string/text(),2,string-length(dia:string/text())-2)" /></b>
  220.                                               <span
  221.                                                class="description">TODO: Add
  222.                                                description of
  223.                                               <xsl:value-of
  224.                                                select="substring(dia:string/text(),2, string-length(dia:string/text())-2)" />
  225.                                                here.</span>
  226.                                             </xsl:if>
  227.                                           </xsl:if>
  228.                                         </xsl:for-each>
  229.                                       </div>    
  230.                               </xsl:otherwise>
  231.                                 </xsl:choose>
  232.                           </xsl:if>
  233.                             </xsl:for-each>
  234.  
  235.                             </xsl:if>
  236.                           </xsl:if>
  237.                         </xsl:for-each>
  238.                       </xsl:if>
  239.                     </xsl:if>
  240.  
  241.                   </xsl:for-each>
  242.  
  243.                   <div
  244.                    class="details"
  245.                    style="display='none'">
  246.                     <ul>
  247.                       <xsl:for-each
  248.                        select="dia:composite">
  249.                         <li>
  250.                         <xsl:for-each
  251.                          select="dia:attribute">
  252.                           <xsl:if
  253.                            test="./@name='name'">
  254.                             <xsl:value-of
  255.                              select="substring(dia:string/text(),2, string-length(dia:string/text())-2)" />
  256.                           </xsl:if>
  257.                         </xsl:for-each>
  258.  
  259.                         <xsl:text>: </xsl:text>
  260.                         <xsl:for-each
  261.                          select="dia:attribute">
  262.                           <xsl:if
  263.                            test="./@name='type'">
  264.                             <i>
  265.                               <span
  266.                                class="datatype">
  267.                                 <xsl:value-of
  268.                                  select="substring(dia:string/text(),2, string-length(dia:string/text())-2)" />
  269.                               </span>
  270.                             </i>
  271.  
  272.                             <xsl:for-each
  273.                              select="../dia:attribute">
  274.                               <xsl:if
  275.                                test="./@name='name'">
  276.                                 <span
  277.                                  class="description">TODO: Add
  278.                                 description of
  279.                                 <xsl:value-of
  280.                                  select="substring(dia:string/text(),2, string-length(dia:string/text())-2)" />
  281.  
  282.                                 here.</span>
  283.                               </xsl:if>
  284.                             </xsl:for-each>
  285.                           </xsl:if>
  286.                         </xsl:for-each>
  287.                         </li>
  288.                       </xsl:for-each>
  289.                     </ul>
  290.                   </div>
  291.                 </xsl:if>
  292.               </xsl:for-each>
  293.             </xsl:element><!-- class header -->
  294.           </xsl:if>
  295.     </xsl:for-each>
  296. </xsl:if>
  297.         </xsl:for-each>
  298.       </body>
  299. <script language="JavaScript1.2" src="ua.js"></script><script type="text/javascript" language="JavaScript1.2">
  300. if(navigator.family=="gecko") {
  301.   var nodeList = document.getElementsByTagName("div");
  302.   for(var i=1; i!= nodeList.length; i++) {
  303.     if(nodeList.item(i).getAttribute("id")!="") {
  304.       toggleVisibility("test", nodeList.item(i).getAttribute("id"));
  305.     }
  306.   }
  307. }
  308. </script>
  309.     </html>
  310.   </xsl:template>
  311. </xsl:stylesheet>
  312.