master
  1<?xml version="1.0" encoding="utf-8"?>
  2<xsl:stylesheet version="1.0"
  3                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  5                xmlns:g="http://www.gallio.org/"
  6                xmlns="http://www.w3.org/1999/xhtml">
  7  <!-- Common utility functions -->
  8  
  9  <!-- Formats a statistics line like 5 run, 3 passed, 2 failed (1 error), 0 inconclusive, 2 skipped -->
 10  <xsl:template name="format-statistics">
 11    <xsl:param name="statistics" />
 12       
 13		<xsl:value-of select="$statistics/@runCount"/>    
 14    <xsl:text> run, </xsl:text>
 15    
 16    <xsl:value-of select="$statistics/@passedCount"/>
 17    <xsl:text> passed</xsl:text>
 18    <xsl:call-template name="format-statistics-category-counts">
 19      <xsl:with-param name="statistics" select="$statistics" />
 20      <xsl:with-param name="status">passed</xsl:with-param>
 21    </xsl:call-template>
 22    <xsl:text>, </xsl:text>
 23    
 24    <xsl:value-of select="$statistics/@failedCount"/>
 25    <xsl:text> failed</xsl:text>
 26    <xsl:call-template name="format-statistics-category-counts">
 27      <xsl:with-param name="statistics" select="$statistics" />
 28      <xsl:with-param name="status">failed</xsl:with-param>
 29    </xsl:call-template>
 30    <xsl:text>, </xsl:text>
 31
 32    <xsl:value-of select="$statistics/@inconclusiveCount"/>
 33    <xsl:text> inconclusive</xsl:text>
 34    <xsl:call-template name="format-statistics-category-counts">
 35      <xsl:with-param name="statistics" select="$statistics" />
 36      <xsl:with-param name="status">inconclusive</xsl:with-param>
 37    </xsl:call-template>
 38    <xsl:text>, </xsl:text>
 39    
 40    <xsl:value-of select="$statistics/@skippedCount"/>
 41    <xsl:text> skipped</xsl:text>
 42    <xsl:call-template name="format-statistics-category-counts">
 43      <xsl:with-param name="statistics" select="$statistics" />
 44      <xsl:with-param name="status">skipped</xsl:with-param>
 45    </xsl:call-template>
 46  </xsl:template>
 47  
 48  <xsl:template name="format-statistics-category-counts">
 49    <xsl:param name="statistics" />
 50    <xsl:param name="status" />
 51    
 52    <xsl:variable name="outcomeSummaries" select="$statistics/g:outcomeSummaries/g:outcomeSummary[g:outcome/@status=$status and g:outcome/@category]" />
 53    
 54    <xsl:if test="$outcomeSummaries">
 55      <xsl:text> (</xsl:text>
 56        <xsl:for-each select="$outcomeSummaries">
 57          <xsl:sort data-type="text" order="ascending" select="g:outcome/@category"/>
 58          
 59          <xsl:if test="position() != 1"><xsl:text>, </xsl:text></xsl:if>
 60          <xsl:value-of select="@count"/>
 61          <xsl:text> </xsl:text>
 62          <xsl:value-of select="g:outcome/@category"/>
 63        </xsl:for-each>
 64      <xsl:text>)</xsl:text>
 65    </xsl:if>
 66  </xsl:template>
 67  
 68  <!-- Creates an aggregate statistics summary from a test instance run and its descendants -->
 69  <xsl:template name="aggregate-statistics">
 70    <xsl:param name="test" />
 71    <xsl:param name="testStepRun" />
 72    
 73    <xsl:variable name="testCaseResults" select="$testStepRun/descendant-or-self::g:testStepRun[g:testStep/@isTestCase='true']/g:result" />
 74    <xsl:variable name="testCaseOutcomes" select="$testCaseResults/g:outcome" />
 75    
 76    <xsl:variable name="skippedOutcomes" select="$testCaseOutcomes[@status = 'skipped']" />
 77    <xsl:variable name="passedOutcomes" select="$testCaseOutcomes[@status = 'passed']" />
 78    <xsl:variable name="inconclusiveOutcomes" select="$testCaseOutcomes[@status = 'inconclusive']" />
 79    <xsl:variable name="failedOutcomes" select="$testCaseOutcomes[@status = 'failed']" />
 80    
 81    <xsl:variable name="skippedCount" select="count($skippedOutcomes)"/>
 82    <xsl:variable name="passedCount" select="count($passedOutcomes)"/>
 83    <xsl:variable name="inconclusiveCount" select="count($inconclusiveOutcomes)"/>
 84    <xsl:variable name="failedCount" select="count($failedOutcomes)"/>
 85
 86    <g:statistics>
 87      <xsl:attribute name="duration"><xsl:value-of select="$testStepRun/g:result/@duration"/></xsl:attribute>
 88      <xsl:attribute name="assertCount"><xsl:value-of select="sum($testCaseResults/@assertCount)"/></xsl:attribute>
 89      
 90      <xsl:attribute name="skippedCount"><xsl:value-of select="$skippedCount"/></xsl:attribute>
 91      <xsl:attribute name="passedCount"><xsl:value-of select="$passedCount"/></xsl:attribute>
 92      <xsl:attribute name="inconclusiveCount"><xsl:value-of select="$inconclusiveCount"/></xsl:attribute>
 93      <xsl:attribute name="failedCount"><xsl:value-of select="$failedCount"/></xsl:attribute>
 94      
 95      <xsl:attribute name="runCount"><xsl:value-of select="$passedCount + $inconclusiveCount + $failedCount"/></xsl:attribute>
 96      
 97      <g:outcomeSummaries>
 98        <xsl:call-template name="aggregate-statistics-outcome-summaries">
 99          <xsl:with-param name="status">skipped</xsl:with-param>
100          <xsl:with-param name="outcomes" select="$skippedOutcomes" />
101        </xsl:call-template>
102        <xsl:call-template name="aggregate-statistics-outcome-summaries">
103          <xsl:with-param name="status">passed</xsl:with-param>
104          <xsl:with-param name="outcomes" select="$passedOutcomes" />
105        </xsl:call-template>
106        <xsl:call-template name="aggregate-statistics-outcome-summaries">
107          <xsl:with-param name="status">inconclusive</xsl:with-param>
108          <xsl:with-param name="outcomes" select="$inconclusiveOutcomes" />
109        </xsl:call-template>
110        <xsl:call-template name="aggregate-statistics-outcome-summaries">
111          <xsl:with-param name="status">failed</xsl:with-param>
112          <xsl:with-param name="outcomes" select="$failedOutcomes" />
113        </xsl:call-template>
114      </g:outcomeSummaries>
115    </g:statistics>
116  </xsl:template>
117  
118  <xsl:key name="outcome-category" match="g:outcome" use="@category" />
119  <xsl:template name="aggregate-statistics-outcome-summaries">
120    <xsl:param name="status" />
121    <xsl:param name="outcomes" />
122    
123    <xsl:for-each select="$outcomes[generate-id() = generate-id(key('outcome-category', @category)[1])]">
124      <xsl:variable name="category" select="@category" />
125      <g:outcomeSummary count="{count($outcomes[@category = $category])}">
126        <g:outcome status="{$status}" category="{$category}" />
127      </g:outcomeSummary>
128    </xsl:for-each>
129  </xsl:template>
130  
131  <!-- Indents text using the specified prefix -->
132  <xsl:template name="indent">
133    <xsl:param name="str" />
134    <xsl:param name="prefix" select="'  '" />
135
136    <xsl:if test="$str!=''">
137      <xsl:call-template name="indent-recursive">
138        <xsl:with-param name="str" select="translate($str, '&#9;&#xA;&#xD;', ' &#xA;')" />
139        <xsl:with-param name="prefix" select="$prefix" />
140      </xsl:call-template>
141    </xsl:if>
142  </xsl:template>
143
144  <xsl:template name="indent-recursive">
145    <xsl:param name="str" />
146    <xsl:param name="prefix" />
147
148    <xsl:variable name="line" select="substring-before($str, '&#xA;')" />
149    <xsl:choose>
150      <xsl:when test="$line!=''">
151        <xsl:value-of select="$prefix"/>
152        <xsl:value-of select="$line"/>
153        <xsl:text>&#xA;</xsl:text>
154        <xsl:call-template name="indent-recursive">
155          <xsl:with-param name="str" select="substring-after($str, '&#xA;')" />
156          <xsl:with-param name="prefix" select="$prefix" />
157        </xsl:call-template>
158      </xsl:when>
159      <xsl:otherwise>
160        <xsl:value-of select="$prefix"/>
161        <xsl:value-of select="$str"/>
162        <xsl:text>&#xA;</xsl:text>
163      </xsl:otherwise>
164    </xsl:choose>
165  </xsl:template>
166
167  <!-- Prints text with <br/> elements -->
168  <xsl:template name="print-text-with-line-breaks">
169    <xsl:param name="text" />
170    <xsl:variable name="tail" select="substring-after($text, '&#10;')" />
171
172    <xsl:choose>
173      <xsl:when test="$tail!=''">
174        <xsl:value-of select="substring-before($text, '&#10;')" />
175        <br/>
176        <xsl:call-template name="print-text-with-line-breaks">
177          <xsl:with-param name="text" select="$tail" />
178        </xsl:call-template>
179      </xsl:when>
180      <xsl:otherwise>
181        <xsl:value-of select="$text" />
182      </xsl:otherwise>
183    </xsl:choose>
184  </xsl:template>
185  
186  <!-- Pretty print date time values -->
187  <xsl:template name="format-datetime">
188    <xsl:param name="datetime" />
189    <xsl:value-of select="substring($datetime, 12, 8)" />, <xsl:value-of select="substring($datetime, 1, 10)" />
190  </xsl:template>
191  
192  <!-- Namespace stripping adapted from http://www.xml.com/pub/a/2004/05/05/tr.html -->
193  <xsl:template name="strip-namespace">
194    <xsl:param name="nodes" />
195    <xsl:apply-templates select="msxsl:node-set($nodes)" mode="strip-namespace" />
196  </xsl:template>
197  
198  <xsl:template match="*" mode="strip-namespace">
199    <xsl:element name="{local-name()}" namespace="">
200      <xsl:apply-templates select="@*|node()" mode="strip-namespace"/>
201    </xsl:element>
202  </xsl:template>
203
204  <xsl:template match="@*" mode="strip-namespace">
205    <xsl:attribute name="{local-name()}" namespace="">
206      <xsl:value-of select="."/>
207    </xsl:attribute>
208  </xsl:template>
209
210  <xsl:template match="processing-instruction()|comment()" mode="strip-namespace">
211    <xsl:copy>
212      <xsl:apply-templates select="node()" mode="strip-namespace"/>
213    </xsl:copy>
214  </xsl:template>  
215  
216  <!-- Converting paths to URIs -->
217  <xsl:template name="path-to-uri">
218    <xsl:param name="path" />    
219    <xsl:if test="$path != ''">
220      <xsl:choose>
221        <xsl:when test="starts-with($path, '\')">/</xsl:when>
222        <xsl:when test="starts-with($path, ' ')">%20</xsl:when>
223        <xsl:when test="starts-with($path, '%')">%25</xsl:when>
224        <xsl:otherwise><xsl:value-of select="substring($path, 1, 1)"/></xsl:otherwise>
225      </xsl:choose>
226      <xsl:call-template name="path-to-uri">
227        <xsl:with-param name="path" select="substring($path, 2)" />
228      </xsl:call-template>
229    </xsl:if>
230  </xsl:template>
231</xsl:stylesheet>