Home | History | Annotate | Download | only in xsl
      1 <?xml version="1.0"?>
      2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
      3 
      4 <xsl:output
      5          method="xml" indent="yes"
      6          doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
      7          doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
      8  		encoding="UTF-8"/>
      9 
     10 <xsl:param name="PAGE.TITLE" select="'Findbugs Summary Statistics'" />
     11 <xsl:param name="PAGE.FONT" select="'Arial'" />
     12 <xsl:param name="SUMMARY.HEADER" select="'Findbugs Summary Report'" />
     13 <xsl:param name="SUMMARY.LABEL" select="'Summary Analysis Generated at: '" />
     14 <xsl:param name="PACKAGE.HEADER" select="'Bugs By Package'" />
     15 <xsl:param name="PACKAGE.SORT.LABEL" select="'Sorted by Total Bugs'" />
     16 <xsl:param name="PACKAGE.LABEL" select="'Analysis of Package: '" />
     17 <xsl:param name="DEFAULT.PACKAGE.NAME" select="'default package'" />
     18 <xsl:param name="PACKAGE.BUGCLASS.LABEL" select="'Most Buggy Class in Package with #1 $1:'" />
     19 <xsl:param name="TOTAL.PACKAGES.LABEL" select="'#1 $1 Analyzed'" />
     20 
     21 <xsl:param name="BUGS.SINGLE.LABEL" select="'Bug'" />
     22 <xsl:param name="BUGS.PULURAL.LABEL" select="'Bugs'" />
     23 <xsl:param name="PACKAGE.SINGLE.LABEL" select="'Package'" />
     24 <xsl:param name="PACKAGE.PULURAL.LABEL" select="'Packages'" />
     25 
     26 
     27 <xsl:param name="TABLE.HEADING.TYPE" select="'Type Checked'" />
     28 <xsl:param name="TABLE.HEADING.COUNT" select="'Count'" />
     29 <xsl:param name="TABLE.HEADING.BUGS" select="'Bugs'" />
     30 <xsl:param name="TABLE.HEADING.PERCENT" select="'Percentage'" />
     31 <xsl:param name="TABLE.ROW.OUTER" select="'Outer Classes'" />
     32 <xsl:param name="TABLE.ROW.INNER" select="'Inner Classes'" />
     33 <xsl:param name="TABLE.ROW.INTERFACE" select="'Interfaces'" />
     34 <xsl:param name="TABLE.ROW.TOTAL" select="'Total'" />
     35 <xsl:param name="TABLE.WIDTH" select="'90%'" />
     36 
     37 <xsl:param name="PERCENTAGE.FORMAT" select="'#0.00%'" />
     38 
     39 <!-- This template drives the rest of the output -->
     40 <xsl:template match="/" >
     41   <html>
     42    <!-- JEditorPane gets really angry if it sees this
     43 	WWP: Sorry, this needs to be explained better. Not a valid HTML document without a head.
     44 	 -->
     45    <head><title><xsl:value-of select="$PAGE.TITLE" /></title></head>
     46   <body>
     47     <h1 align="center"><a href="http://findbugs.sourceforge.net"><xsl:value-of select="$SUMMARY.HEADER" /></a></h1>
     48     <h2 align="center"> Analysis for 
     49     <xsl:choose>
     50       <xsl:when test='string-length(/BugCollection/Project/@projectName)>0'>
     51           <xsl:value-of select="/BugCollection/Project/@projectName" /></xsl:when>
     52       <xsl:otherwise><xsl:value-of select="/BugCollection/Project/@filename" /></xsl:otherwise>
     53     </xsl:choose>
     54       </h2>
     55   <h2 align="center"><xsl:value-of select="$SUMMARY.LABEL" /> 
     56       <i><xsl:value-of select="//FindBugsSummary/@timestamp" /></i></h2>
     57   <xsl:apply-templates select="//FindBugsSummary" />
     58   <br/>
     59   <p align="center">
     60   <font face="{$PAGE.FONT}" size="6"><xsl:value-of select="$PACKAGE.HEADER" /></font>
     61     <br/><font face="{$PAGE.FONT}" size="4"><i>(<xsl:value-of select="$PACKAGE.SORT.LABEL"/>)</i></font>
     62   </p>
     63   <xsl:for-each select="//FindBugsSummary/PackageStats">
     64   <xsl:sort select="@total_bugs" data-type="number" order="descending" />
     65   <xsl:apply-templates select="." />
     66   </xsl:for-each>
     67   </body>
     68   </html>
     69 </xsl:template>
     70 
     71 <xsl:template name="status_table_row" >
     72   <xsl:param name="LABEL" select="''" />
     73   <xsl:param name="COUNT" select="1" />
     74   <xsl:param name="BUGS" select="0" />
     75   <xsl:param name="FONT_SIZE" select="4" />
     76   <tr>
     77    <td align="left"><font face="{$PAGE.FONT}" size="{$FONT_SIZE}"><xsl:value-of select="$LABEL" /></font></td>
     78    <td align="center"><font face="{$PAGE.FONT}" color="green" size="{$FONT_SIZE}"><xsl:value-of select="$COUNT" /></font></td>
     79    <td align="center"><font face="{$PAGE.FONT}" color="red" size="{$FONT_SIZE}"><xsl:value-of select="$BUGS" /></font></td>
     80    <td align="center"><font face="{$PAGE.FONT}" color="blue" size="{$FONT_SIZE}">
     81       <xsl:choose>
     82       <xsl:when test="$COUNT &gt; 0">
     83        <xsl:value-of select="format-number(number($BUGS div $COUNT), $PERCENTAGE.FORMAT)"/>
     84       </xsl:when>
     85       <xsl:otherwise>
     86        <xsl:value-of select="format-number(0, $PERCENTAGE.FORMAT)"/>
     87       </xsl:otherwise>
     88       </xsl:choose>
     89      </font>
     90    </td>
     91   </tr>
     92 </xsl:template>
     93 
     94 <xsl:template name="table_header" >
     95   <tr>
     96   <th><font face="{$PAGE.FONT}" size="4"><xsl:value-of select="$TABLE.HEADING.TYPE"/></font></th>
     97   <th><font face="{$PAGE.FONT}" size="4"><xsl:value-of select="$TABLE.HEADING.COUNT"/></font></th>
     98   <th><font face="{$PAGE.FONT}" size="4"><xsl:value-of select="$TABLE.HEADING.BUGS"/></font></th>
     99   <th><font face="{$PAGE.FONT}" size="4"><xsl:value-of select="$TABLE.HEADING.PERCENT"/></font></th>
    100   </tr>
    101 </xsl:template>
    102 
    103 <xsl:template match="FindBugsSummary" >
    104   <table width="{$TABLE.WIDTH}" border="1" align="center">
    105    <xsl:call-template name="table_header" />
    106 
    107    <xsl:call-template name="status_table_row">
    108      <xsl:with-param name="LABEL" select="$TABLE.ROW.OUTER" />
    109      <xsl:with-param name="COUNT" select="count(PackageStats/ClassStats[@interface='false' and substring-after(@class,'$')=''])" />
    110      <xsl:with-param name="BUGS" select="sum(PackageStats/ClassStats[@interface='false' and substring-after(@class,'$')='']/@bugs)" />
    111    </xsl:call-template>
    112 
    113    <xsl:call-template name="status_table_row">
    114      <xsl:with-param name="LABEL" select="$TABLE.ROW.INNER" />
    115      <xsl:with-param name="COUNT" select="count(PackageStats/ClassStats[@interface='false' and substring-after(@class,'$')!=''])" />
    116      <xsl:with-param name="BUGS" select="sum(PackageStats/ClassStats[@interface='false' and substring-after(@class,'$')!='']/@bugs)" />
    117    </xsl:call-template>
    118 
    119    <xsl:call-template name="status_table_row">
    120      <xsl:with-param name="LABEL" select="$TABLE.ROW.INTERFACE" />
    121      <xsl:with-param name="COUNT" select="count(PackageStats/ClassStats[@interface='true'])" />
    122      <xsl:with-param name="BUGS" select="sum(PackageStats/ClassStats[@interface='true']/@bugs)" />
    123    </xsl:call-template>
    124 
    125    <xsl:call-template name="status_table_row">
    126      <xsl:with-param name="LABEL" select="$TABLE.ROW.TOTAL" />
    127      <xsl:with-param name="COUNT" select="@total_classes" />
    128      <xsl:with-param name="BUGS" select="@total_bugs"/>
    129      <xsl:with-param name="FONT_SIZE" select="5"/>
    130    </xsl:call-template>
    131    <xsl:variable name="num_packages" select="count(PackageStats)" />
    132    <tr><td align="center" colspan="4"><font face="{$PAGE.FONT}" size="4">
    133      <xsl:call-template name='string_format'>
    134      <xsl:with-param name="COUNT" select="$num_packages"/>
    135      <xsl:with-param name="STRING" select="$TOTAL.PACKAGES.LABEL"/>
    136      <xsl:with-param name="SINGLE" select="$PACKAGE.SINGLE.LABEL"/>
    137      <xsl:with-param name="PULURAL" select="$PACKAGE.PULURAL.LABEL"/>
    138      </xsl:call-template>
    139      </font></td>
    140    </tr>
    141   </table>
    142 </xsl:template>
    143 
    144 
    145 <xsl:template name='string_format'>
    146   <xsl:param name="COUNT" select="1"/>
    147   <xsl:param name="STRING" select="''"/>
    148   <xsl:param name="SINGLE" select="''"/>
    149   <xsl:param name="PULURAL" select="''"/>
    150   <xsl:variable name="count_str" select="concat(substring-before($STRING,'#1'), $COUNT, substring-after($STRING,'#1'))" />
    151 
    152   <xsl:choose>
    153     <xsl:when test="$COUNT &gt; 1">
    154       <xsl:value-of select="concat(substring-before($count_str,'$1'), $PULURAL, substring-after($count_str,'$1'))" />
    155     </xsl:when>
    156     <xsl:otherwise>
    157     <xsl:value-of select="concat(substring-before($count_str,'$1'), $SINGLE, substring-after($count_str,'$1'))" />
    158     </xsl:otherwise>
    159   </xsl:choose>
    160 </xsl:template>
    161 
    162 
    163 <xsl:template match="PackageStats" >
    164   <xsl:variable name="package-name">
    165     <xsl:choose>
    166       <xsl:when test="@package = ''">
    167         <xsl:value-of select="$DEFAULT.PACKAGE.NAME"/>
    168       </xsl:when>
    169       <xsl:otherwise>
    170         <xsl:value-of select="@package"/>
    171       </xsl:otherwise>
    172     </xsl:choose>
    173   </xsl:variable>
    174   <xsl:variable name="package-prefix">
    175     <xsl:choose>
    176       <xsl:when test="@package = ''">
    177         <xsl:text></xsl:text>
    178       </xsl:when>
    179       <xsl:otherwise>
    180         <xsl:value-of select="concat(@package,'.')"/>
    181       </xsl:otherwise>
    182     </xsl:choose>
    183   </xsl:variable>
    184   <h2 align="center"><xsl:value-of select="$PACKAGE.LABEL"/><i><font color='green'><xsl:value-of select="$package-name" /></font></i></h2>
    185    <table width="{$TABLE.WIDTH}" border="1" align="center">
    186    <xsl:call-template name="table_header" />
    187 
    188    <xsl:call-template name="status_table_row">
    189      <xsl:with-param name="LABEL" select="$TABLE.ROW.OUTER" />
    190      <xsl:with-param name="COUNT" select="count(ClassStats[@interface='false' and substring-after(@class,'$')=''])" />
    191      <xsl:with-param name="BUGS" select="sum(ClassStats[@interface='false' and substring-after(@class,'$')='']/@bugs)" />
    192    </xsl:call-template>
    193 
    194    <xsl:call-template name="status_table_row">
    195      <xsl:with-param name="LABEL" select="$TABLE.ROW.INNER" />
    196      <xsl:with-param name="COUNT" select="count(ClassStats[@interface='false' and substring-after(@class,'$')!=''])" />
    197      <xsl:with-param name="BUGS" select="sum(ClassStats[@interface='false' and substring-after(@class,'$')!='']/@bugs)" />
    198    </xsl:call-template>
    199 
    200    <xsl:call-template name="status_table_row">
    201      <xsl:with-param name="LABEL" select="$TABLE.ROW.INTERFACE" />
    202      <xsl:with-param name="COUNT" select="count(ClassStats[@interface='true'])" />
    203      <xsl:with-param name="BUGS" select="sum(ClassStats[@interface='true']/@bugs)" />
    204    </xsl:call-template>
    205 
    206    <xsl:call-template name="status_table_row">
    207      <xsl:with-param name="LABEL" select="$TABLE.ROW.TOTAL" />
    208      <xsl:with-param name="COUNT" select="@total_types" />
    209      <xsl:with-param name="BUGS" select="@total_bugs" />
    210      <xsl:with-param name="FONT_SIZE" select="5"/>
    211    </xsl:call-template>
    212 
    213   </table>
    214   <xsl:if test="@total_bugs &gt; 0">
    215   <table width="{$TABLE.WIDTH}" border="0" align="center">
    216      <xsl:variable name="max_bugs">
    217        <xsl:for-each select="ClassStats">
    218          <xsl:sort select="@bugs" data-type="number" order="descending"/>
    219          <xsl:if test="position()=1">
    220            <xsl:value-of select="@bugs"/>
    221          </xsl:if>
    222        </xsl:for-each>
    223      </xsl:variable>
    224 
    225      <tr>
    226        <td align="left" colspan="2">
    227          <font face="{$PAGE.FONT}" size="4">
    228      <xsl:call-template name='string_format'>
    229      <xsl:with-param name="COUNT" select="$max_bugs"/>
    230      <xsl:with-param name="STRING" select="$PACKAGE.BUGCLASS.LABEL"/>
    231      <xsl:with-param name="SINGLE" select="$BUGS.SINGLE.LABEL"/>
    232      <xsl:with-param name="PULURAL" select="$BUGS.PULURAL.LABEL"/>
    233      </xsl:call-template>
    234          </font>
    235        </td>
    236      </tr>
    237 
    238      <xsl:for-each select="ClassStats">
    239        <xsl:if test="@bugs = $max_bugs">
    240        <tr>
    241           <td>&#160;&#160;&#160;&#160;&#160;&#160;&#160;</td>
    242           <td align="left"><font face="{$PAGE.FONT}" color="red" size="4"><i><xsl:value-of select="$package-prefix"/><xsl:value-of select="@class" /></i></font></td>
    243        </tr>
    244        </xsl:if>
    245      </xsl:for-each>
    246 
    247    </table>
    248   </xsl:if>
    249   <br/>
    250 </xsl:template>
    251 
    252 </xsl:stylesheet>
    253