PageRenderTime 118ms CodeModel.GetById 112ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/NCover/Coverage.xsl

http://github.com/agross/netopenspace
Extensible Stylesheet Language Transformations | 339 lines | 333 code | 6 blank | 0 comment | 0 complexity | 7360d7ca19067a9ac9b95053785acfa0 MD5 | raw file
  1<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
  2  <!-- saved from url=(0022)http://www.ncover.org/ -->
  3  <!-- created by Yves Lorphelin, largely inspired by the nunitsumary.xsl (see nantcontrib.sourceforge.net)-->
  4	<xsl:template match="coverage">
  5		<html>
  6			<head>
  7				<title>NCover Code Coverage Report</title>
  8				<style>
  9          BODY {
 10          font: small verdana, arial, helvetica;
 11          color:#000000;
 12          }
 13
 14          P {
 15          line-height:1.5em;
 16          margin-top:0.5em; margin-bottom:1.0em;
 17          }
 18          H1 {
 19          MARGIN: 0px 0px 5px;
 20          FONT: bold larger arial, verdana, helvetica;
 21
 22          }
 23          H2 {
 24          MARGIN-TOP: 1em; MARGIN-BOTTOM: 0.5em;
 25          FONT: larger verdana,arial,helvetica
 26          }
 27          H3 {
 28          MARGIN-BOTTOM: 0.5em; FONT: bold 13px verdana,arial,helvetica
 29          }
 30          H4 {
 31          MARGIN-BOTTOM: 0.5em; FONT: bold 100% verdana,arial,helvetica
 32          }
 33          H5 {
 34          MARGIN-BOTTOM: 0.5em; FONT: bold 100% verdana,arial,helvetica
 35          }
 36          H6 {
 37          MARGIN-BOTTOM: 0.5em; FONT: bold 100% verdana,arial,helvetica
 38          }
 39          .notVisited { background:red; }
 40          .excluded { background: skyblue; }
 41          .visited { background: #90ee90; }
 42          .title { font-size: 12px; font-weight: bold; }
 43          .assembly { font-size: normal;   font-weight: bold; font-size: 11px}
 44          .class {font-size:normal; cursor: hand; color: #444444; font-size: 11px}
 45          .module { color: navy; font-size: 12px; }
 46          .method {cursor: hand; color: ; font-size: 10px; font-weight: bold; }
 47          .subtitle { color: black; font-size: 10px; font-weight: bold; }
 48          .hdrcell  {font-size:9px; background-color: #DDEEFF; }
 49          .datacell {font-size:9px; background-color: #FFFFEE; text-align: right; }
 50          .hldatacell {font-size:9px; background-color: #FFCCCC; text-align: right; }
 51          .exdatacell {font-size:9px; background-color: #DDEEFF; text-align: right; }
 52          .detailPercent {  font-size: 9px; font-weight: bold; padding-top: 1px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px;}
 53        </style>
 54				<script language="JavaScript"><![CDATA[   
 55				function toggle (field)	
 56				{ field.style.display = (field.style.display == "block") ? "none" : "block"; }  
 57				
 58				function SwitchAll(how)
 59				{	var len = document.all.length-1;
 60					for(i=0;i!=len;i++)	{	
 61						var block = document.all[i];
 62						if (block != null && block.id != '')
 63						{ block.style.display=how;}
 64					}
 65				}
 66
 67
 68				function ExpandAll()
 69				{SwitchAll('block');}
 70		
 71				function CollapseAll()
 72				{SwitchAll('none');}
 73				]]></script>
 74			</head>
 75			<body>
 76				<a name="#top"></a>
 77				<xsl:call-template name="header" />
 78				<xsl:call-template name="ModuleSummary" />
 79				<xsl:call-template name="module" />
 80				<xsl:call-template name="footer" />
 81				<script language="JavaScript">CollapseAll();</script>
 82			</body>
 83		</html>
 84	</xsl:template>
 85	<xsl:template name="module">
 86		<xsl:for-each select="//module">
 87			<xsl:sort select="@assembly" />
 88			<xsl:variable name="module" select="./@assembly" />
 89			<div class="assembly">
 90				<a name="#{generate-id($module)}">Module 
 91					<xsl:value-of select="$module" />
 92				</a>
 93			</div>
 94			<xsl:for-each select="./method[not(./@class = preceding-sibling::method/@class)]">
 95				<xsl:sort select="@class" />
 96				<xsl:sort select="@name" />
 97				<xsl:call-template name="ClassSummary">
 98					<xsl:with-param name="module" select="$module" />
 99					<xsl:with-param name="class" select="./@class" />
100				</xsl:call-template>
101			</xsl:for-each>
102		</xsl:for-each>
103		<xsl:variable name="totalMod" select="count(./method/seqpnt[@excluded='false'])" />
104		<xsl:variable name="notvisitedMod" select="count( ./method/seqpnt[ @visitcount='0'][@excluded='false'] ) div $totalMod * 100 " />
105		<xsl:variable name="visitedMod" select="count(./method/seqpnt[not(@visitcount='0')] ) div $totalMod * 100" />
106	</xsl:template>
107	<xsl:template name="Methods">
108		<xsl:param name="module" />
109		<xsl:param name="class" />
110		<xsl:for-each select="//method[(@class = $class) and (parent::module/@assembly=$module)]">
111			<xsl:sort select="@name" />
112			<xsl:variable name="total" select="count(./seqpnt[@excluded='false'])" />
113			<xsl:variable name="notvisited" select="count(./seqpnt[@visitcount='0'][@excluded='false'] ) " />
114			<xsl:variable name="visited" select="count(./seqpnt[not(@visitcount='0')])" />
115			<xsl:variable name="methid" select="generate-id(.)" />
116			<table cellpadding="3" cellspacing="0" width="90%">
117				<tr>
118					<td width="45%" class='method'>
119						<xsl:attribute name="onclick">javascript:toggle(
120							<xsl:value-of select="$methid" />)
121						</xsl:attribute>
122						<xsl:value-of select="@name" />
123					</td>
124					<td width="55%">
125						<xsl:call-template name="detailPercent">
126							<xsl:with-param name="visited" select="$visited" />
127							<xsl:with-param name="notVisited" select="$notvisited" />
128							<xsl:with-param name="total" select="$total" />
129						</xsl:call-template>
130					</td>
131				</tr>
132			</table>
133			<xsl:call-template name="seqpnt">
134				<xsl:with-param name="module" select="$module" />
135				<xsl:with-param name="class" select="$class" />
136				<xsl:with-param name="id" select="$methid" />
137			</xsl:call-template>
138		</xsl:for-each>
139	</xsl:template>
140	<xsl:template name="seqpnt">
141		<xsl:param name="module" />
142		<xsl:param name="class" />
143		<xsl:param name="id" />
144		<table cellpadding="3" cellspacing="0" border='1' width="90%" bordercolor="black" style="display: block;">
145			<xsl:attribute name="id">
146				<xsl:value-of select="$id" />
147			</xsl:attribute>
148			<tr>
149				<td class="hdrcell">Visits</td>
150				<td class="hdrcell">Line</td>
151				<td class="hdrcell">End</td>
152				<td class="hdrcell">Column</td>
153				<td class="hdrcell">End</td>
154				<td class="hdrcell">Document</td>
155			</tr>
156			<xsl:for-each select="./seqpnt">
157				<xsl:sort select="@line" />
158				<tr>
159					<td class="datacell">
160						<xsl:attribute name="class">
161							<xsl:choose>
162                <xsl:when test="@excluded = 'true'">exdatacell</xsl:when>
163                <xsl:when test="@visitcount = 0">hldatacell</xsl:when>
164								<xsl:otherwise>datacell</xsl:otherwise>
165							</xsl:choose>
166						</xsl:attribute>
167            <xsl:choose>
168              <xsl:when test="@excluded = 'true'">---</xsl:when>
169              <xsl:otherwise><xsl:value-of select="@visitcount" /></xsl:otherwise>
170            </xsl:choose>
171					</td>
172					<td class="datacell">
173						<xsl:value-of select="@line" />
174					</td>
175					<td class="datacell">
176						<xsl:value-of select="@endline" />
177					</td>
178					<td class="datacell">
179						<xsl:value-of select="@column" />
180					</td>
181					<td class="datacell">
182						<xsl:value-of select="@endcolumn" />
183					</td>
184					<td class="datacell">
185						<xsl:value-of select="@document" />
186					</td>
187				</tr>
188			</xsl:for-each>
189		</table>
190	</xsl:template>
191	<!-- Class Summary -->
192	<xsl:template name="ClassSummary">
193		<xsl:param name="module" />
194		<xsl:param name="class" />
195		<xsl:variable name="total" select="count(//seqpnt[(parent::method/parent::module/@assembly=$module) and (parent::method/@class=$class) and (@excluded='false') ])" />
196		<xsl:variable name="notvisited" select="count(//seqpnt[(parent::method/parent::module/@assembly=$module)and (parent::method/@class=$class) and (@visitcount='0') and (@excluded='false')] )" />
197		<xsl:variable name="visited" select="count(//seqpnt[(parent::method/parent::module/@assembly=$module) and (parent::method/@class=$class) and (not(@visitcount='0'))] )" />
198		<xsl:variable name="newid" select="concat (generate-id(), 'class')" />
199		<table width='90%'>
200			<tr>
201				<td width="40%" class="class">
202					<xsl:attribute name="onclick">javascript:toggle(
203						<xsl:value-of select="$newid" />)
204					</xsl:attribute>
205					<xsl:value-of select="$class" />
206				</td>
207				<td width="60%">
208					<xsl:call-template name="detailPercent">
209						<xsl:with-param name="visited" select="$visited" />
210						<xsl:with-param name="notVisited" select="$notvisited" />
211						<xsl:with-param name="total" select="$total" />
212					</xsl:call-template>
213				</td>
214			</tr>
215			<tr>
216				<table style="display: block;" width="100%">
217					<tr>
218						<td>
219							<xsl:attribute name="id">
220								<xsl:value-of select="$newid" />
221							</xsl:attribute>
222							<xsl:call-template name="Methods">
223								<xsl:with-param name="module" select="$module" />
224								<xsl:with-param name="class" select="$class" />
225							</xsl:call-template>
226						</td>
227					</tr>
228				</table>
229			</tr>
230		</table>
231		<hr size="1" width='90%' align='left' style=" border-bottom: 1px dotted #999;" />
232	</xsl:template>
233	<xsl:template name="ClassSummaryDetail">
234		<xsl:param name="module" />
235		<xsl:variable name="total" select="count(./method/seqpnt[ @excluded='false' ])" />
236		<xsl:variable name="notVisited" select="count( ./method/seqpnt[ @visitcount='0'][ @excluded='false' ] )" />
237		<xsl:variable name="visited" select="count(./method/seqpnt[not(@visitcount='0')] )" />
238		<td width="35%">
239			<div class="assembly">
240				<a href="#{generate-id($module)}">
241					<xsl:value-of select="$module" />
242				</a>
243			</div>
244		</td>
245		<td width="65%">
246			<xsl:call-template name="detailPercent">
247				<xsl:with-param name="visited" select="$visited" />
248				<xsl:with-param name="notVisited" select="$notVisited" />
249				<xsl:with-param name="total" select="$total" />
250			</xsl:call-template>
251		</td>
252	</xsl:template>
253	<!-- Modules Summary -->
254	<xsl:template name="ModuleSummary">
255		<H2>Modules summary</H2>
256		<xsl:for-each select="//module">
257			<xsl:sort select="@assembly" />
258			<table width='90%'>
259				<tr>
260					<xsl:call-template name="ModuleSummaryDetail">
261						<xsl:with-param name="module" select="./@assembly" />
262					</xsl:call-template>
263				</tr>
264			</table>
265		</xsl:for-each>
266		<hr size="1" />
267	</xsl:template>
268	<xsl:template name="ModuleSummaryDetail">
269		<xsl:param name="module" />
270		<xsl:variable name="total" select="count(./method/seqpnt[@excluded='false'])" />
271		<xsl:variable name="notVisited" select="count( ./method/seqpnt[ @visitcount='0' ][ @excluded='false' ] )" />
272		<xsl:variable name="visited" select="count(./method/seqpnt[not(@visitcount='0')] )" />
273		<td width="30%">
274			<div class="assembly">
275				<a href="#{generate-id($module)}">
276					<xsl:value-of select="$module" />
277				</a>
278			</div>
279		</td>
280		<td width="70%">
281			<xsl:call-template name="detailPercent">
282				<xsl:with-param name="visited" select="$visited" />
283				<xsl:with-param name="notVisited" select="$notVisited" />
284				<xsl:with-param name="total" select="$total" />
285			</xsl:call-template>
286		</td>
287	</xsl:template>
288	<!-- General Header -->
289	<xsl:template name="header">
290		<h1>
291			<b>NCover</b> Code Coverage Report
292		</h1>
293		<table>
294			<tr>
295				<td class="class">
296					<a onClick="ExpandAll();">Expand</a>
297				</td>
298				<td> | </td>
299				<td class="class">
300					<a onClick="CollapseAll();">Collapse</a>
301				</td>
302			</tr>
303		</table>
304		<hr size="1" />
305	</xsl:template>
306	<xsl:template name="footer">
307		<hr size="1" />
308		<a class="detailPercent" href="#{top}">Top</a>
309	</xsl:template>
310	<!-- draw % table-->
311	<xsl:template name="detailPercent">
312		<xsl:param name="visited" />
313		<xsl:param name="notVisited" />
314		<xsl:param name="total" />
315		<table width="100%" class="detailPercent">
316			<tr>
317        <xsl:if test="($notVisited=0) and ($visited=0)">
318          <td class="excluded" width="100%">Excluded</td>
319        </xsl:if>
320        <xsl:if test="not($notVisited=0)">
321					<td class="notVisited">
322						<xsl:attribute name="width">
323							<xsl:value-of select="concat($notVisited div $total * 100,'%')" />
324						</xsl:attribute>
325						<xsl:value-of select="concat (format-number($notVisited div $total * 100,'#.##'),'%')" />
326					</td>
327				</xsl:if>
328				<xsl:if test="not ($visited=0)">
329					<td class="visited">
330						<xsl:attribute name="width">
331							<xsl:value-of select="concat($visited div $total * 100,'%')" />
332						</xsl:attribute>
333						<xsl:value-of select="concat (format-number($visited div $total * 100,'#.##'), '%')" />
334					</td>
335				</xsl:if>
336			</tr>
337		</table>
338	</xsl:template>
339</xsl:stylesheet>