2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
3 xmlns:exsl="http://exslt.org/common"
4 xmlns:str="http://exslt.org/strings"
5 xmlns:date="http://exslt.org/dates-and-times"
6 extension-element-prefixes="exsl str date">
7 <xsl:include href="str.replace.function.xsl"/>
8 <xsl:output method="html" indent="yes" encoding="US-ASCII"/>
9 <xsl:decimal-format decimal-separator="." grouping-separator=","/>
11 Copyright 2001-2004 The Apache Software Foundation
13 Licensed under the Apache License, Version 2.0 (the "License");
14 you may not use this file except in compliance with the License.
15 You may obtain a copy of the License at
17 http://www.apache.org/licenses/LICENSE-2.0
19 Unless required by applicable law or agreed to in writing, software
20 distributed under the License is distributed on an "AS IS" BASIS,
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 See the License for the specific language governing permissions and
23 limitations under the License.
28 Sample stylesheet to be used with Phing/PHPUnit output.
29 Based on JUnit stylesheets from Apache Ant.
31 It creates a set of HTML files a la javadoc where you can browse easily
32 through all packages and classes.
34 @author Michiel Rook <a href="mailto:michiel.rook@gmail.com"/>
35 @author Stephane Bailliez <a href="mailto:sbailliez@apache.org"/>
36 @author Erik Hatcher <a href="mailto:ehatcher@apache.org"/>
37 @author Martijn Kruithof <a href="mailto:martijn@kruithof.xs4all.nl"/>
40 <xsl:param name="output.dir" select="'.'"/>
41 <xsl:param name="output.sorttable" select="'.'"/>
44 <xsl:template match="testsuites">
45 <!-- create the index.html -->
46 <exsl:document href="efile://{$output.dir}/index.html">
47 <xsl:call-template name="index.html"/>
50 <!-- create the stylesheet.css -->
51 <exsl:document omit-xml-declaration="yes" href="efile://{$output.dir}/stylesheet.css">
52 <xsl:call-template name="stylesheet.css"/>
55 <!-- create the overview-packages.html at the root -->
56 <exsl:document href="efile://{$output.dir}/overview-summary.html">
57 <xsl:apply-templates select="." mode="overview.packages"/>
60 <!-- create the all-packages.html at the root -->
61 <exsl:document href="efile://{$output.dir}/overview-frame.html">
62 <xsl:apply-templates select="." mode="all.packages"/>
65 <!-- create the all-classes.html at the root -->
66 <exsl:document href="efile://{$output.dir}/allclasses-frame.html">
67 <xsl:apply-templates select="." mode="all.classes"/>
70 <!-- process all packages -->
71 <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
72 <xsl:call-template name="package">
73 <xsl:with-param name="name" select="@package"/>
79 <xsl:template name="package">
80 <xsl:param name="name"/>
81 <xsl:variable name="package.dir">
82 <xsl:if test="not($name = '')"><xsl:value-of select="translate($name,'.','/')"/></xsl:if>
83 <xsl:if test="$name = ''">.</xsl:if>
85 <!--Processing package <xsl:value-of select="@name"/> in <xsl:value-of select="$output.dir"/> -->
86 <!-- create a classes-list.html in the package directory -->
87 <exsl:document href="efile://{$output.dir}/{$package.dir}/package-frame.html">
88 <xsl:call-template name="classes.list">
89 <xsl:with-param name="name" select="$name"/>
93 <!-- create a package-summary.html in the package directory -->
94 <exsl:document href="efile://{$output.dir}/{$package.dir}/package-summary.html">
95 <xsl:call-template name="package.summary">
96 <xsl:with-param name="name" select="$name"/>
100 <!-- for each class, creates a @name.html -->
101 <!-- @bug there will be a problem with inner classes having the same name, it will be overwritten -->
102 <xsl:for-each select="/testsuites/testsuite[@package = $name]">
103 <exsl:document href="efile://{$output.dir}/{$package.dir}/{@name}.html">
104 <xsl:apply-templates select="." mode="class.details"/>
106 <xsl:if test="string-length(./system-out)!=0">
107 <exsl:document href="efile://{$output.dir}/{$package.dir}/{@name}-out.txt">
108 <xsl:value-of select="./system-out" />
111 <xsl:if test="string-length(./system-err)!=0">
112 <exsl:document href="efile://{$output.dir}/{$package.dir}/{@name}-err.txt">
113 <xsl:value-of select="./system-err" />
119 <xsl:template name="index.html">
122 <title>Unit Test Results.</title>
124 <frameset cols="20%,80%">
125 <frameset rows="30%,70%">
126 <frame src="overview-frame.html" name="packageListFrame"/>
127 <frame src="allclasses-frame.html" name="classListFrame"/>
129 <frame src="overview-summary.html" name="classFrame"/>
133 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.
140 <!-- this is the stylesheet css to use for nearly everything -->
141 <xsl:template name="stylesheet.css">
143 font-family: verdana,arial,helvetica;
147 table tr td, table tr th {
148 font-family: verdana,arial,helvetica;
152 font-family: verdana,arial,helvetica;
163 margin-top:0.5em; margin-bottom:1.0em;
168 font-family: verdana,arial,helvetica;
171 margin-top: 1em; margin-bottom: 0.5em;
172 font-family: verdana,arial,helvetica;
175 margin-bottom: 0.5em;
176 font-family: verdana,arial,helvetica;
179 margin-bottom: 0.5em;
180 font-family: verdana,arial,helvetica;
183 margin-bottom: 0.5em;
184 font-family: verdana,arial,helvetica;
187 margin-bottom: 0.5em;
188 font-family: verdana,arial,helvetica;
191 font-weight:bold; color:red;
194 font-weight:bold; color:purple;
205 <xsl:if test="$output.sorttable = 1">
213 <!-- ======================================================================
214 This page is created for every testsuite class.
215 It prints a summary of the testsuite and detailed information about
217 ====================================================================== -->
218 <xsl:template match="testsuite" mode="class.details">
219 <xsl:variable name="package.name" select="@package"/>
220 <xsl:variable name="class.name"><xsl:if test="not($package.name = '')"><xsl:value-of select="$package.name"/>.</xsl:if><xsl:value-of select="@name"/></xsl:variable>
223 <title>Unit Test Results: Class <xsl:value-of select="$class.name"/></title>
224 <xsl:if test="$output.sorttable = 1">
225 <script language="JavaScript" src="http://www.phing.info/support/sorttable.js"/>
227 <xsl:call-template name="create.stylesheet.link">
228 <xsl:with-param name="package.name" select="$package.name"/>
232 <xsl:call-template name="pageHeader"/>
233 <h3>Class <xsl:value-of select="$class.name"/></h3>
235 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
236 <xsl:call-template name="testsuite.test.header"/>
237 <xsl:apply-templates select="." mode="print.test"/>
241 <table class="details sortable" border="0" cellpadding="5" cellspacing="2" width="95%">
242 <xsl:call-template name="testcase.test.header"/>
244 test can even not be started at all (failure to load the class)
245 so report the error directly
247 <xsl:if test="./error">
249 <td colspan="4"><xsl:apply-templates select="./error"/></td>
252 <xsl:apply-templates select="./testcase | ./testsuite/testcase" mode="print.test"/>
254 <xsl:call-template name="pageFooter"/>
259 <!-- ======================================================================
260 This page is created for every package.
261 It prints the name of all classes that belongs to this package.
262 @param name the package name to print classes.
263 ====================================================================== -->
264 <!-- list of classes in a package -->
265 <xsl:template name="classes.list">
266 <xsl:param name="name"/>
269 <title>Unit Test Classes: <xsl:value-of select="$name"/></title>
270 <xsl:call-template name="create.stylesheet.link">
271 <xsl:with-param name="package.name" select="$name"/>
278 <h2><a href="package-summary.html" target="classFrame">
279 <xsl:value-of select="$name"/>
280 <xsl:if test="$name = ''"><none></xsl:if>
288 <xsl:for-each select="/testsuites/testsuite[./@package = $name]">
289 <xsl:sort select="@name"/>
292 <a href="{@name}.html" target="classFrame"><xsl:value-of select="@name"/></a>
303 Creates an all-classes.html file that contains a link to all package-summary.html
306 <xsl:template match="testsuites" mode="all.classes">
309 <title>All Unit Test Classes</title>
310 <xsl:call-template name="create.stylesheet.link">
311 <xsl:with-param name="package.name"/>
317 <xsl:apply-templates select="testsuite" mode="all.classes">
318 <xsl:sort select="@name"/>
319 </xsl:apply-templates>
325 <xsl:template match="testsuite" mode="all.classes">
326 <xsl:variable name="package.name" select="@package"/>
329 <a target="classFrame">
330 <xsl:attribute name="href">
331 <xsl:if test="not($package.name='')">
332 <xsl:value-of select="translate($package.name,'.','/')"/><xsl:text>/</xsl:text>
333 </xsl:if><xsl:value-of select="@name"/><xsl:text>.html</xsl:text>
335 <xsl:value-of select="@name"/>
343 Creates an html file that contains a link to all package-summary.html files on
344 each package existing on testsuites.
345 @bug there will be a problem here, I don't know yet how to handle unnamed package :(
347 <xsl:template match="testsuites" mode="all.packages">
350 <title>All Unit Test Packages</title>
351 <xsl:call-template name="create.stylesheet.link">
352 <xsl:with-param name="package.name"/>
356 <h2><a href="overview-summary.html" target="classFrame">Home</a></h2>
359 <xsl:apply-templates select="testsuite[not(./@package = preceding-sibling::testsuite/@package)]" mode="all.packages">
360 <xsl:sort select="@package"/>
361 </xsl:apply-templates>
367 <xsl:template match="testsuite" mode="all.packages">
370 <a href="./{translate(@package,'.','/')}/package-summary.html" target="classFrame">
371 <xsl:value-of select="@package"/>
372 <xsl:if test="@package = ''"><none></xsl:if>
379 <xsl:template match="testsuites" mode="overview.packages">
382 <title>Unit Test Results: Summary</title>
383 <xsl:if test="$output.sorttable = 1">
384 <script language="JavaScript" src="http://www.phing.info/support/sorttable.js"/>
386 <xsl:call-template name="create.stylesheet.link">
387 <xsl:with-param name="package.name"/>
391 <xsl:attribute name="onload">open('allclasses-frame.html','classListFrame')</xsl:attribute>
392 <xsl:call-template name="pageHeader"/>
394 <xsl:variable name="testCount" select="sum(testsuite/@tests)"/>
395 <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
396 <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/>
397 <xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
398 <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/>
399 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
404 <th>Success rate</th>
408 <xsl:attribute name="class">
410 <xsl:when test="$errorCount > 0">Error</xsl:when>
411 <xsl:when test="$failureCount > 0">Failure</xsl:when>
412 <xsl:otherwise>Pass</xsl:otherwise>
415 <td><xsl:value-of select="$testCount"/></td>
416 <td><xsl:value-of select="$failureCount"/></td>
417 <td><xsl:value-of select="$errorCount"/></td>
419 <xsl:call-template name="display-percent">
420 <xsl:with-param name="value" select="$successRate"/>
424 <xsl:call-template name="display-time">
425 <xsl:with-param name="value" select="$timeCount"/>
431 <table border="0" width="95%">
433 <td style="text-align: justify;">
434 Note: <em>failures</em> are anticipated and checked for with assertions while <em>errors</em> are unanticipated.
440 <table class="details sortable" border="0" cellpadding="5" cellspacing="2" width="95%">
441 <xsl:call-template name="testsuite.test.header"/>
442 <xsl:for-each select="testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
443 <xsl:sort select="@package" order="ascending"/>
444 <!-- get the node set containing all testsuites that have the same package -->
445 <xsl:variable name="insamepackage" select="/testsuites/testsuite[./@package = current()/@package]"/>
447 <!-- display a failure if there is any failure/error in the package -->
448 <xsl:attribute name="class">
450 <xsl:when test="sum($insamepackage/@errors) > 0">Error</xsl:when>
451 <xsl:when test="sum($insamepackage/@failures) > 0">Failure</xsl:when>
452 <xsl:otherwise>Pass</xsl:otherwise>
455 <td><a href="./{translate(@package,'.','/')}/package-summary.html">
456 <xsl:value-of select="@package"/>
457 <xsl:if test="@package = ''"><none></xsl:if>
459 <td><xsl:value-of select="sum($insamepackage/@tests)"/></td>
460 <td><xsl:value-of select="sum($insamepackage/@errors)"/></td>
461 <td><xsl:value-of select="sum($insamepackage/@failures)"/></td>
463 <xsl:call-template name="display-time">
464 <xsl:with-param name="value" select="sum($insamepackage/@time)"/>
470 <xsl:call-template name="pageFooter"/>
476 <xsl:template name="package.summary">
477 <xsl:param name="name"/>
480 <title>Unit Test Results: Package <xsl:value-of select="$name"/></title>
481 <xsl:if test="$output.sorttable = 1">
482 <script language="JavaScript" src="http://www.phing.info/support/sorttable.js"/>
484 <xsl:call-template name="create.stylesheet.link">
485 <xsl:with-param name="package.name" select="$name"/>
489 <xsl:attribute name="onload">open('package-frame.html','classListFrame')</xsl:attribute>
490 <xsl:call-template name="pageHeader"/>
491 <h3>Package <xsl:value-of select="$name"/></h3>
493 <!--table border="0" cellpadding="5" cellspacing="2" width="95%">
494 <xsl:call-template name="class.metrics.header"/>
495 <xsl:apply-templates select="." mode="print.metrics"/>
498 <xsl:variable name="insamepackage" select="/testsuites/testsuite[./@package = $name]"/>
499 <xsl:if test="count($insamepackage) > 0">
502 <table class="details sortable" border="0" cellpadding="5" cellspacing="2" width="95%">
503 <xsl:call-template name="testsuite.test.header"/>
504 <xsl:apply-templates select="$insamepackage" mode="print.test">
505 <xsl:sort select="@name"/>
506 </xsl:apply-templates>
510 <xsl:call-template name="pageFooter"/>
517 transform string like a.b.c to ../../../
518 @param path the path to transform into a descending directory path
520 <xsl:template name="path">
521 <xsl:param name="path"/>
522 <xsl:if test="contains($path,'.')">
523 <xsl:text>../</xsl:text>
524 <xsl:call-template name="path">
525 <xsl:with-param name="path"><xsl:value-of select="substring-after($path,'.')"/></xsl:with-param>
528 <xsl:if test="not(contains($path,'.')) and not($path = '')">
529 <xsl:text>../</xsl:text>
534 <!-- create the link to the stylesheet based on the package name -->
535 <xsl:template name="create.stylesheet.link">
536 <xsl:param name="package.name"/>
537 <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>
542 <xsl:template name="pageHeader">
543 <h1>Unit Test Results</h1>
546 <td align="left"></td>
547 <td align="right">Designed for use with <a href='http://www.phpunit.de'>PHPUnit</a> and <a href='http://www.phing.info/'>Phing</a>.</td>
554 <xsl:template name="pageFooter">
556 <tr><td><hr noshade="yes" size="1"/></td></tr>
557 <tr><td class="small">Report generated at <xsl:value-of select="date:date-time()"/></td></tr>
561 <!-- class header -->
562 <xsl:template name="testsuite.test.header">
564 <th width="80%">Name</th>
568 <th nowrap="nowrap">Time(s)</th>
572 <!-- method header -->
573 <xsl:template name="testcase.test.header">
577 <th width="80%">Type</th>
578 <th nowrap="nowrap">Time(s)</th>
583 <!-- class information -->
584 <xsl:template match="testsuite" mode="print.test">
586 <xsl:attribute name="class">
588 <xsl:when test="@errors[.> 0]">Error</xsl:when>
589 <xsl:when test="@failures[.> 0]">Failure</xsl:when>
590 <xsl:otherwise>Pass</xsl:otherwise>
593 <td><a href="{@name}.html"><xsl:value-of select="@name"/></a></td>
594 <td><xsl:apply-templates select="@tests"/></td>
595 <td><xsl:apply-templates select="@errors"/></td>
596 <td><xsl:apply-templates select="@failures"/></td>
597 <td><xsl:call-template name="display-time">
598 <xsl:with-param name="value" select="@time"/>
604 <xsl:template match="testcase" mode="print.test">
606 <xsl:attribute name="class">
608 <xsl:when test="error">Error</xsl:when>
609 <xsl:when test="failure">Failure</xsl:when>
610 <xsl:otherwise>TableRowColor</xsl:otherwise>
613 <td><xsl:value-of select="@name"/></td>
615 <xsl:when test="failure">
617 <td><xsl:apply-templates select="failure"/></td>
619 <xsl:when test="error">
621 <td><xsl:apply-templates select="error"/></td>
629 <xsl:call-template name="display-time">
630 <xsl:with-param name="value" select="@time"/>
637 <!-- Note : the below template error and failure are the same style
638 so just call the same style store in the toolkit template -->
639 <xsl:template match="failure">
640 <xsl:call-template name="display-failures"/>
643 <xsl:template match="error">
644 <xsl:call-template name="display-failures"/>
647 <!-- Style for the error and failure in the testcase template -->
648 <xsl:template name="display-failures">
650 <xsl:when test="not(@message)">N/A</xsl:when>
652 <xsl:value-of select="@message"/>
655 <!-- display the stacktrace -->
658 <xsl:call-template name="br-replace">
659 <xsl:with-param name="word" select="."/>
665 template that will convert a carriage return into a br tag
666 @param word the text from which to convert CR to BR tag
668 <xsl:template name="br-replace">
669 <xsl:param name="word"/>
671 <xsl:when test="contains($word,'
')">
672 <xsl:value-of select="substring-before($word,'
')"/>
674 <xsl:call-template name="br-replace">
675 <xsl:with-param name="word" select="substring-after($word,'
')"/>
679 <xsl:value-of select="$word"/>
684 <xsl:template name="display-time">
685 <xsl:param name="value"/>
686 <xsl:value-of select="format-number($value,'0.000')"/>
689 <xsl:template name="display-percent">
690 <xsl:param name="value"/>
691 <xsl:value-of select="format-number($value,'0.00%')"/>