Home | History | Annotate | Download | only in coverage
      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <xsl:stylesheet
      3   version="1.0"
      4   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      5   >
      6   <xsl:output
      7     method="xml"
      8     omit-xml-declaration="yes"
      9     indent="yes"
     10     encoding="UTF-8"
     11     doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
     12     doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
     13     xmlns="http://www.w3.org/1999/xhtml"
     14     />
     15 
     16   <xsl:template match="/CoverageReport">
     17     <html lang="en" xml:lang="en">
     18       <head>
     19         <title>Coverage report</title>
     20         <style type="text/css">
     21           <xsl:text disable-output-escaping="yes">
     22             .progressbar .percent.excelent {
     23               background-color: green;
     24             }
     25             #tree .element.good > .name,
     26             .progressbar .percent.good,
     27             .demo .good {
     28               background-color: greenyellow;
     29             }
     30             #tree .element.nice > .name,
     31             .progressbar .percent.nice,
     32             .demo .nice {
     33               background-color: yellow;
     34             }
     35             #tree .element.bad > .name,
     36             .progressbar .percent.bad,
     37             .demo .bad {
     38               background-color: orange;
     39             }
     40             #tree .element.critical > .name,
     41             .progressbar .percent.critical,
     42             .demo .critical {
     43               background-color: orangeRed;
     44             }
     45             #tree .element input:checked ~ .children {
     46               display: block !important;
     47             }
     48             #tree .element input ~ .children {
     49               display: none;
     50             }
     51 
     52             table, table td {
     53               border-width: 1px;
     54               border-style: solid dotted solid dotted;
     55               border-color: silver;
     56               border-collapse: collapse;
     57               padding-left: 0.2em;
     58               padding-right: 0.2em;
     59             }
     60             .progressbar {
     61               width: 20em;
     62             }
     63 
     64             .progressbar .percent {
     65               display: inline-block;
     66               height: 0.5em;
     67               vertical-align: middle;
     68             }
     69             div.description:nth-of-type(2n+1) {
     70               background-color: whitesmoke;
     71             }
     72             tr:hover {
     73               background-color: lightyellow;
     74             }
     75           </xsl:text>
     76         </style>
     77         <meta http-equiv="content-type" content="text/html;charset=utf-8" />
     78       </head>
     79       <body>
     80         <h1>Coverage report</h1>
     81         <h2>Summary</h2>
     82         <table class="summary">
     83           <xsl:apply-templates select=".|*" mode="summary" />
     84         </table>
     85 
     86         <h2>Legend</h2>
     87           <p>Colors correspond to:</p>
     88           <table class="demo">
     89             <xsl:call-template name="legend-color">
     90               <xsl:with-param name="coverage">100</xsl:with-param>
     91               <xsl:with-param name="description">Full coverage</xsl:with-param>
     92             </xsl:call-template>
     93             <xsl:call-template name="legend-color">
     94               <xsl:with-param name="coverage">75</xsl:with-param>
     95               <xsl:with-param name="description">
     96                 <xsl:text>75%-99% coverage, nice</xsl:text>
     97               </xsl:with-param>
     98             </xsl:call-template>
     99             <xsl:call-template name="legend-color">
    100               <xsl:with-param name="coverage">50</xsl:with-param>
    101               <xsl:with-param name="description">Half the way !</xsl:with-param>
    102             </xsl:call-template>
    103             <xsl:call-template name="legend-color">
    104               <xsl:with-param name="coverage">0</xsl:with-param>
    105               <xsl:with-param name="description">Forgot something ?</xsl:with-param>
    106             </xsl:call-template>
    107           </table>
    108 
    109         <h2>Tree</h2>
    110         <!-- Warning IE conditional comment. A warning is displayed if using IE,
    111            as the tree view has been reported not to work on IE7. ("&lt!" ==  "<") -->
    112         <xsl:comment>
    113           <xsl:text>[if IE]>
    114             &lt;span class="warning" style="background-color: red;font-weight:bold;" >
    115               This tree representation has been reported not to work on IE.
    116               Please use a navigator that respect standards.
    117             &lt;/span>
    118           &lt;![endif]</xsl:text>
    119         </xsl:comment>
    120         <p>Check/Uncheck the checkboxes to fold/unfold.</p>
    121         <ul class="tree" id="tree">
    122           <xsl:apply-templates select="." mode="tree" />
    123         </ul>
    124 
    125         <h2>Description</h2>
    126         <div class="descriptions">
    127           <xsl:apply-templates select=".|descendant::*" mode="description" />
    128         </div>
    129       </body>
    130     </html>
    131   </xsl:template>
    132 
    133   <!--##############
    134     summary templates
    135     ##############-->
    136   <xsl:template mode="summary" match="*">
    137     <tr>
    138       <td>
    139         <a href="#description-{generate-id(.)}">
    140           <xsl:apply-templates select="." mode="summary-name" />
    141         </a>
    142       </td>
    143       <td><xsl:value-of select="@Coverage" /></td>
    144       <xsl:apply-templates select="." mode="progress-bar" />
    145     </tr>
    146   </xsl:template>
    147 
    148   <xsl:template mode="summary-name" match="/*" >
    149     <xsl:text>Coverage total average</xsl:text>
    150   </xsl:template>
    151   <xsl:template mode="summary-name" match="*">
    152     <xsl:value-of select="name()" />
    153   </xsl:template>
    154 
    155   <xsl:template name="legend-color">
    156     <xsl:param name="coverage" />
    157     <xsl:param name="description" />
    158     <tr>
    159       <td class="coverage">
    160         <xsl:attribute name="class">
    161           <xsl:call-template name="choose-quality">
    162             <xsl:with-param name="coverage">
    163               <xsl:value-of select="$coverage" />
    164             </xsl:with-param>
    165           </xsl:call-template>
    166         </xsl:attribute>
    167         <xsl:value-of select="$coverage" />
    168       </td>
    169       <td class="coverage">
    170         <xsl:value-of select="$description" />
    171       </td>
    172     </tr>
    173   </xsl:template>
    174 
    175   <!-- quality coverage templates -->
    176   <xsl:template name="quality">
    177     <xsl:call-template name="choose-quality">
    178       <xsl:with-param name="coverage">
    179         <xsl:value-of select="number(substring-before(@Coverage,'%'))" />
    180       </xsl:with-param>
    181     </xsl:call-template>
    182   </xsl:template>
    183 
    184   <xsl:template name="choose-quality">
    185     <xsl:param name="coverage" />
    186     <xsl:choose>
    187       <xsl:when test="$coverage >= 100">excelent</xsl:when>
    188       <xsl:when test="$coverage >= 75">nice</xsl:when>
    189       <xsl:when test="$coverage >= 50">bad</xsl:when>
    190       <xsl:when test="$coverage >= 0">critical</xsl:when>
    191       <xsl:otherwise />
    192     </xsl:choose>
    193   </xsl:template>
    194 
    195 
    196   <!--##############
    197     Tree templates
    198     ##############-->
    199 
    200   <!-- Ignore the CriterionState nodes and childrens
    201      as it add a huge number of unimportant info-->
    202   <xsl:template mode="tree" match="CriterionStates" />
    203 
    204   <xsl:template mode="tree" match="*">
    205     <li id="tree-{generate-id(.)}">
    206 
    207       <xsl:attribute name="class">
    208         <xsl:text>element </xsl:text>
    209         <xsl:call-template name="quality" />
    210       </xsl:attribute>
    211 
    212       <xsl:apply-templates select="." mode="tree-checkbox" />
    213       <a class="name description" href="#description-{generate-id(.)}">
    214         <xsl:value-of select="@Name" />
    215       </a>
    216 
    217       <xsl:if test="node()">
    218         <ul class="children"><xsl:apply-templates select="*" mode="tree" /></ul>
    219       </xsl:if>
    220     </li>
    221   </xsl:template>
    222 
    223   <xsl:template mode="tree-checkbox" match="ConfigurableDomain | Criterion">
    224     <input class="description" type="checkbox" />
    225   </xsl:template>
    226   <xsl:template mode="tree-checkbox" match="Domains | Criteria">
    227     <input class="description" type="checkbox" checked="checked" />
    228   </xsl:template>
    229   <xsl:template mode="tree-checkbox" match="*" />
    230 
    231   <!--####################
    232     Description templates
    233     ####################-->
    234   <!-- Ignore the CriterionState nodes and childrens
    235      as it add a huge number of unimportant info-->
    236   <xsl:template mode="description" match="CriterionStates|CriterionStates//*" />
    237 
    238   <xsl:template mode="description" match="*">
    239     <div class="description">
    240       <h3 id="description-{generate-id(.)}">
    241         <xsl:value-of select="@Name" />
    242       </h3>
    243       <p>
    244         <xsl:text>Path:</xsl:text>
    245         <xsl:apply-templates select="ancestor::*|." mode="path" />
    246       </p>
    247       <a class="name" href="#tree-{generate-id(.)}">
    248         <xsl:text>Back to tree</xsl:text>
    249       </a>
    250       <h4>Detail</h4>
    251       <table>
    252         <xsl:if test="parent::*">
    253           <tr>
    254             <td>Type</td>
    255             <td><xsl:value-of select="name()" /></td>
    256           </tr>
    257           <tr>
    258             <td>Parent</td>
    259             <td>
    260               <a class="name" href="#description-{generate-id(..)}">
    261                 <xsl:value-of select="../@Name" />
    262               </a>
    263               <xsl:text> (</xsl:text>
    264               <xsl:value-of select="name(..)" />
    265               <xsl:text>)</xsl:text>
    266             </td>
    267           </tr>
    268         </xsl:if>
    269         <xsl:apply-templates select="./@*" mode="description" />
    270       </table>
    271       <xsl:if test="node()">
    272         <h4>Children</h4>
    273         <table>
    274           <tr>
    275             <th>Name</th>
    276             <th>Type</th>
    277             <th>Coverage</th>
    278             <th>Nb use</th>
    279             <th>Coverage progress bar</th>
    280           </tr>
    281           <xsl:apply-templates select="*" mode="description-children" />
    282         </table>
    283       </xsl:if>
    284     </div>
    285   </xsl:template>
    286 
    287   <xsl:template mode="path" match="*">
    288     <xsl:text> / </xsl:text>
    289     <a href="#description-{generate-id(.)}"><xsl:value-of select="@Name" /></a>
    290   </xsl:template>
    291 
    292   <xsl:template match="@*" mode="description">
    293     <tr>
    294       <td><xsl:value-of select="name()" /></td>
    295       <td><xsl:value-of select="." /></td>
    296     </tr>
    297   </xsl:template>
    298 
    299 
    300   <!-- Ignore the CriterionState nodes as it add a huge number of unimportant info-->
    301   <xsl:template mode="description-children" match="CriterionStates" />
    302 
    303   <xsl:template mode="description-children" match="*">
    304     <tr>
    305       <td><a class="name" href="#description-{generate-id(.)}">
    306         <xsl:value-of select="@Name" />
    307       </a></td>
    308       <td><xsl:value-of select="name()" /></td>
    309       <xsl:apply-templates select="./@*" mode="description-children" />
    310       <xsl:apply-templates select="." mode="progress-bar" />
    311     </tr>
    312   </xsl:template>
    313 
    314   <xsl:template match="@Name" mode="description-children" />
    315   <xsl:template match="@*" mode="description-children">
    316     <td><xsl:value-of select="." /></td>
    317   </xsl:template>
    318 
    319   <xsl:template mode="progress-bar" match="*">
    320     <td class="progressbar">
    321       <span style="width:{@Coverage}">
    322         <xsl:attribute name="class">
    323           <xsl:text>percent </xsl:text>
    324           <xsl:call-template name="quality" />
    325         </xsl:attribute>
    326       </span>
    327     </td>
    328   </xsl:template>
    329 </xsl:stylesheet>
    330