1 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
2 xmlns:exsl="http://exslt.org/common"
3 xmlns:date="http://exslt.org/dates-and-times"
4 extension-element-prefixes="exsl date">
5 <xsl:output method="html" indent="yes"/>
6 <xsl:decimal-format decimal-separator="." grouping-separator="," />
8 Copyright 2001-2004 The Apache Software Foundation
10 Licensed under the Apache License, Version 2.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
26 Sample stylesheet to be used with Xdebug/Phing code coverage output.
27 Based on JProbe stylesheets from Apache Ant.
29 It creates a set of HTML files a la javadoc where you can browse easily
30 through all packages and classes.
32 @author Michiel Rook <a href="mailto:michiel.rook@gmail.com"/>
33 @author Stephane Bailliez <a href="mailto:sbailliez@apache.org"/>
37 <!-- default output directory is current directory -->
38 <xsl:param name="output.dir" select="'.'"/>
40 <!-- ======================================================================
42 ======================================================================= -->
43 <xsl:template match="/snapshot">
44 <!-- create the index.html -->
45 <exsl:document href="efile://{$output.dir}/index.html">
46 <xsl:call-template name="index.html"/>
49 <!-- create the stylesheet.css -->
50 <exsl:document href="efile://{$output.dir}/stylesheet.css">
51 <xsl:call-template name="stylesheet.css"/>
54 <!-- create the overview-packages.html at the root -->
55 <exsl:document href="efile://{$output.dir}/overview-summary.html">
56 <xsl:apply-templates select="." mode="overview.packages"/>
59 <!-- create the all-packages.html at the root -->
60 <exsl:document href="efile://{$output.dir}/overview-frame.html">
61 <xsl:apply-templates select="." mode="all.packages"/>
64 <!-- create the all-classes.html at the root -->
65 <exsl:document href="efile://{$output.dir}/allclasses-frame.html">
66 <xsl:apply-templates select="." mode="all.classes"/>
69 <!-- process all packages -->
70 <xsl:apply-templates select="./package" mode="write"/>
73 <!-- =======================================================================
74 Frameset definition. Entry point for the report.
75 3 frames: packageListFrame, classListFrame, classFrame
76 ======================================================================= -->
77 <xsl:template name="index.html">
79 <head><title>Coverage Results.</title></head>
80 <frameset cols="20%,80%">
81 <frameset rows="30%,70%">
82 <frame src="overview-frame.html" name="packageListFrame"/>
83 <frame src="allclasses-frame.html" name="classListFrame"/>
85 <frame src="overview-summary.html" name="classFrame"/>
90 This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
96 <!-- =======================================================================
98 ======================================================================= -->
99 <!-- this is the stylesheet css to use for nearly everything -->
100 <xsl:template name="stylesheet.css">
108 background-color:#FFFFFF;
109 font-family: verdana,arial,sanserif;
137 table.log tr td, tr th {
149 text-decoration: none;
159 FONT-SIZE: 2px; BACKGROUND: #c0c0c0; BORDER:#9c9c9c 1px solid;
163 FONT-SIZE: 2px; BACKGROUND: #00df00; BORDER:#9c9c9c 1px solid;
167 FONT-SIZE: 2px; BACKGROUND: #00df00; BORDER-LEFT:#9c9c9c 1px solid;BORDER-TOP:#9c9c9c 1px solid;BORDER-BOTTOM:#9c9c9c 1px solid;
171 FONT-SIZE: 2px; BACKGROUND: #df0000; BORDER:#9c9c9c 1px solid;
175 BACKGROUND: #ffffff; MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px;
177 PRE.srcLineHighLight {
178 BACKGROUND: #F0C8C8; MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px;
180 td.lineCount, td.coverageCount {
181 BACKGROUND: #F0F0F0; PADDING-RIGHT: 3px;
184 td.lineCountHighlight {
185 background: #C8C8F0; PADDING-RIGHT: 3px;
188 td.coverageCountHighlight {
189 background: #F0C8C8; PADDING-RIGHT: 3px;
192 td.srcLineHighlight {
198 TD.srcLineClassStart {
199 WIDTH: 100%; BORDER-TOP:#dcdcdc 1px solid; FONT-WEIGHT: bold;
201 .srcLine , .srcLine ol, .srcLine ol li {margin: 0;}
202 .srcLine .de1, .srcLine .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;}
203 .srcLine .imp {font-weight: bold; color: red;}
204 .srcLine .kw1 {color: #b1b100;}
205 .srcLine .kw2 {color: #000000; font-weight: bold;}
206 .srcLine .kw3 {color: #000066;}
207 .srcLine .co1 {color: #808080; font-style: italic;}
208 .srcLine .co2 {color: #808080; font-style: italic;}
209 .srcLine .coMULTI {color: #808080; font-style: italic;}
210 .srcLine .es0 {color: #000099; font-weight: bold;}
211 .srcLine .br0 {color: #66cc66;}
212 .srcLine .st0 {color: #ff0000;}
213 .srcLine .nu0 {color: #cc66cc;}
214 .srcLine .me1 {color: #006600;}
215 .srcLine .me2 {color: #006600;}
216 .srcLine .re0 {color: #0000ff;}
219 <!-- =======================================================================
220 List of all classes in all packages
221 This will be the first page in the classListFrame
222 ======================================================================= -->
223 <xsl:template match="snapshot" mode="all.classes">
226 <xsl:call-template name="create.stylesheet.link"/>
231 <xsl:for-each select="package/class">
232 <xsl:sort select="@name"/>
233 <xsl:variable name="package.name" select="(ancestor::package)[last()]/@name"/>
234 <xsl:variable name="link">
235 <xsl:if test="not($package.name='')">
236 <xsl:value-of select="translate($package.name,'.','/')"/><xsl:text>/</xsl:text>
237 </xsl:if><xsl:value-of select="@name"/><xsl:text>.html</xsl:text>
241 <a target="classFrame" href="{$link}"><xsl:value-of select="@name"/></a>
243 <xsl:when test="@totalcount=0">
247 <i> (<xsl:value-of select="format-number(@totalcovered div @totalcount, '0.0%')"/>)</i>
258 <!-- list of all packages -->
259 <xsl:template match="snapshot" mode="all.packages">
262 <xsl:call-template name="create.stylesheet.link"/>
265 <h2><a href="overview-summary.html" target="classFrame">Overview</a></h2>
266 <h2>All Packages</h2>
268 <xsl:for-each select="package">
269 <xsl:sort select="@name" order="ascending"/>
272 <a href="{translate(@name,'.','/')}/package-summary.html" target="classFrame">
273 <xsl:value-of select="@name"/>
283 <!-- overview of statistics in packages -->
284 <xsl:template match="snapshot" mode="overview.packages">
287 <xsl:call-template name="create.stylesheet.link"/>
289 <body onload="open('allclasses-frame.html','classListFrame')">
290 <xsl:call-template name="pageHeader"/>
291 <table class="log" cellpadding="5" cellspacing="0" width="100%">
293 <td class="small">Packages: <xsl:value-of select="count(package)"/></td>
294 <td class="small">Classes: <xsl:value-of select="count(package/class)"/></td>
295 <td class="small">Methods: <xsl:value-of select="@methodcount"/></td>
296 <td class="small">LOC: <xsl:value-of select="count(package/class/sourcefile/sourceline)"/></td>
297 <td class="small">Statements: <xsl:value-of select="@statementcount"/></td>
302 <table class="log" cellpadding="5" cellspacing="0" width="100%">
304 <th width="100%" nowrap="nowrap"></th>
307 <th width="350" colspan="2" nowrap="nowrap">Total coverage</th>
310 <td><b>Project</b></td>
311 <xsl:call-template name="stats.formatted"/>
314 <td colspan="3"><br/></td>
317 <th width="100%">Packages</th>
320 <th width="350" colspan="2" nowrap="nowrap">Total coverage</th>
322 <!-- display packages and sort them via their coverage rate -->
323 <xsl:for-each select="package">
324 <xsl:sort data-type="number" select="@totalcovered div @totalcount"/>
326 <xsl:call-template name="alternate-row"/>
327 <td><a href="{translate(@name,'.','/')}/package-summary.html"><xsl:value-of select="@name"/></a></td>
328 <xsl:call-template name="stats.formatted"/>
332 <xsl:call-template name="pageFooter"/>
338 detailed info for a package. It will output the list of classes
339 , the summary page, and the info for each class
341 <xsl:template match="package" mode="write">
342 <xsl:variable name="package.dir">
343 <xsl:if test="not(@name = '')"><xsl:value-of select="translate(@name,'.','/')"/></xsl:if>
344 <xsl:if test="@name = ''">.</xsl:if>
347 <!-- create a classes-list.html in the package directory -->
348 <exsl:document href="efile://{$output.dir}/{$package.dir}/package-frame.html">
349 <xsl:apply-templates select="." mode="classes.list"/>
352 <!-- create a package-summary.html in the package directory -->
353 <exsl:document href="efile://{$output.dir}/{$package.dir}/package-summary.html">
354 <xsl:apply-templates select="." mode="package.summary"/>
357 <!-- for each class, creates a @name.html -->
358 <xsl:for-each select="class">
359 <exsl:document href="efile://{$output.dir}/{$package.dir}/{@name}.html">
360 <xsl:apply-templates select="." mode="class.details"/>
365 <!-- list of classes in a package -->
366 <xsl:template match="package" mode="classes.list">
369 <xsl:call-template name="create.stylesheet.link">
370 <xsl:with-param name="package.name" select="@name"/>
377 <H2><a href="package-summary.html" target="classFrame"><xsl:value-of select="@name"/></a></H2>
384 <xsl:for-each select="class">
385 <xsl:sort select="@name"/>
388 <a href="{@name}.html" target="classFrame"><xsl:value-of select="@name"/></a>
390 <xsl:when test="@totalcount=0">
394 <i>(<xsl:value-of select="format-number(@totalcovered div @totalcount, '0.0%')"/>)</i>
405 <!-- summary of a package -->
406 <xsl:template match="package" mode="package.summary">
409 <xsl:call-template name="create.stylesheet.link">
410 <xsl:with-param name="package.name" select="@name"/>
413 <!-- when loading this package, it will open the classes into the frame -->
414 <BODY onload="open('package-frame.html','classListFrame')">
415 <xsl:call-template name="pageHeader"/>
416 <table class="log" cellpadding="5" cellspacing="0" width="100%">
418 <td class="small">Classes: <xsl:value-of select="count(class)"/></td>
419 <td class="small">Methods: <xsl:value-of select="@methodcount"/></td>
420 <td class="small">LOC: <xsl:value-of select="count(class/sourcefile/sourceline)"/></td>
421 <td class="small">Statements: <xsl:value-of select="@statementcount"/></td>
426 <table class="log" cellpadding="5" cellspacing="0" width="100%">
428 <th width="100%">Package</th>
431 <th width="350" colspan="2" nowrap="nowrap">Total coverage</th>
433 <xsl:apply-templates select="." mode="stats"/>
435 <xsl:if test="count(class) > 0">
437 <td colspan="3"><br/></td>
440 <th width="100%">Classes</th>
443 <th width="350" colspan="2" nowrap="nowrap">Total coverage</th>
445 <xsl:apply-templates select="class" mode="stats">
446 <xsl:sort data-type="number" select="@totalcovered div @totalcount"/>
447 </xsl:apply-templates>
450 <xsl:call-template name="pageFooter"/>
455 <!-- details of a class -->
456 <xsl:template match="class" mode="class.details">
457 <xsl:variable name="package.name" select="(ancestor::package)[last()]/@name"/>
460 <xsl:call-template name="create.stylesheet.link">
461 <xsl:with-param name="package.name" select="$package.name"/>
465 <xsl:call-template name="pageHeader"/>
466 <table class="log" cellpadding="5" cellspacing="0" width="100%">
468 <td class="small">Methods: <xsl:value-of select="@methodcount"/></td>
469 <td class="small">LOC: <xsl:value-of select="count(sourcefile/sourceline)"/></td>
470 <td class="small">Statements: <xsl:value-of select="@statementcount"/></td>
475 <!-- class summary -->
476 <table class="log" cellpadding="5" cellspacing="0" width="100%">
478 <th width="100%">Source file</th>
481 <th width="250" colspan="2" nowrap="nowrap">Total coverage</th>
484 <xsl:call-template name="alternate-row"/>
485 <td><xsl:value-of select="sourcefile/@name"/></td>
486 <xsl:call-template name="stats.formatted"/>
489 <table cellspacing="0" cellpadding="0" width="100%">
490 <xsl:apply-templates select="sourcefile/sourceline"/>
493 <xsl:call-template name="pageFooter"/>
500 <xsl:template name="pageHeader">
501 <!-- jakarta logo -->
502 <table border="0" cellpadding="0" cellspacing="0" width="100%">
504 <td class="bannercell" rowspan="2">
505 <a href="http://phing.info/">
506 <img src="http://phing.info/images/phing.gif" alt="http://phing.info/" align="left" border="0"/>
509 <td style="text-align:right"><h2>Source Code Coverage</h2></td>
512 <td style="text-align:right">Designed for use with <a href='http://pear.php.net/package/PHPUnit2'>PHPUnit2</a>, <a href='http://www.xdebug.org/'>Xdebug</a> and <a href='http://phing.info/'>Phing</a>.</td>
519 <xsl:template name="pageFooter">
521 <tr><td><hr noshade="yes" size="1"/></td></tr>
522 <tr><td class="small">Report generated at <xsl:value-of select="date:date-time()"/></td></tr>
526 <xsl:template match="package" mode="stats">
528 <xsl:call-template name="alternate-row"/>
529 <td><xsl:value-of select="@name"/></td>
530 <xsl:call-template name="stats.formatted"/>
534 <xsl:template match="class" mode="stats">
536 <xsl:call-template name="alternate-row"/>
537 <td><a href="{@name}.html" target="classFrame"><xsl:value-of select="@name"/></a></td>
538 <xsl:call-template name="stats.formatted"/>
542 <xsl:template name="stats.formatted">
544 <xsl:when test="@statementcount=0">
549 <xsl:value-of select="format-number(@statementscovered div @statementcount,'0.0%')"/>
554 <xsl:when test="@methodcount=0">
559 <xsl:value-of select="format-number(@methodscovered div @methodcount,'0.0%')"/>
564 <xsl:when test="@totalcount=0">
567 <table cellspacing="0" cellpadding="0" border="0" width="100%" style="display: inline">
569 <td class="empty" width="200" height="12"> </td>
576 <xsl:value-of select="format-number(@totalcovered div @totalcount,'0.0%')"/>
579 <xsl:variable name="leftwidth"><xsl:value-of select="format-number((@totalcovered * 200) div @totalcount,'0')"/></xsl:variable>
580 <xsl:variable name="rightwidth"><xsl:value-of select="format-number(200 - (@totalcovered * 200) div @totalcount,'0')"/></xsl:variable>
581 <table cellspacing="0" cellpadding="0" border="0" width="100%" style="display: inline">
584 <xsl:when test="$leftwidth=200">
585 <td class="fullcover" width="200" height="12"> </td>
588 <xsl:if test="not($leftwidth=0)">
589 <td class="covered" width="{$leftwidth}" height="12"> </td>
591 <xsl:if test="not($rightwidth=0)">
592 <td class="uncovered" width="{$rightwidth}" height="12"> </td>
603 <xsl:template match="sourceline">
605 <xsl:if test="@coveredcount>0">
606 <td class="lineCountHighlight"><xsl:value-of select="position()"/></td>
607 <td class="lineCountHighlight"><xsl:value-of select="@coveredcount"/></td>
609 <xsl:if test="@coveredcount<0">
610 <td class="lineCountHighlight"><xsl:value-of select="position()"/></td>
611 <td class="coverageCountHighlight">0</td>
613 <xsl:if test="@coveredcount=0">
614 <td class="lineCount"><xsl:value-of select="position()"/></td>
615 <td class="coverageCount"></td>
618 <xsl:if test="@startclass=1">
619 <xsl:attribute name="class">srcLineClassStart</xsl:attribute>
621 <xsl:if test="@coveredcount>0">
622 <pre class="srcLine"><xsl:value-of select="."/></pre>
624 <xsl:if test="@coveredcount<0">
625 <pre class="srcLineHighlight"><xsl:value-of select="."/></pre>
627 <xsl:if test="@coveredcount=0">
628 <pre class="srcLine"><xsl:value-of select="."/></pre>
635 transform string like a.b.c to ../../../
636 @param path the path to transform into a descending directory path
638 <xsl:template name="path">
639 <xsl:param name="path"/>
640 <xsl:if test="contains($path,'.')">
641 <xsl:text>../</xsl:text>
642 <xsl:call-template name="path">
643 <xsl:with-param name="path"><xsl:value-of select="substring-after($path,'.')"/></xsl:with-param>
646 <xsl:if test="not(contains($path,'.')) and not($path = '')">
647 <xsl:text>../</xsl:text>
652 <!-- create the link to the stylesheet based on the package name -->
653 <xsl:template name="create.stylesheet.link">
654 <xsl:param name="package.name"/>
655 <LINK REL ="stylesheet" TYPE="text/css" TITLE="Style"><xsl:attribute name="href"><xsl:if test="not($package.name = 'unnamed package')"><xsl:call-template name="path"><xsl:with-param name="path" select="$package.name"/></xsl:call-template></xsl:if>stylesheet.css</xsl:attribute></LINK>
658 <!-- alternated row style -->
659 <xsl:template name="alternate-row">
660 <xsl:attribute name="class">
661 <xsl:if test="position() mod 2 = 1">a</xsl:if>
662 <xsl:if test="position() mod 2 = 0">b</xsl:if>