summaryrefslogtreecommitdiffstats
path: root/tools/coverage/coverage.xsl
blob: a9861b92414fae8336cd46b9d142d3d8876a5161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  >
  <xsl:output
    method="xml"
    omit-xml-declaration="yes"
    indent="yes"
    encoding="UTF-8"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    xmlns="http://www.w3.org/1999/xhtml"
    />

  <xsl:template match="/CoverageReport">
    <html lang="en" xml:lang="en">
      <head>
        <title>Coverage report</title>
        <style type="text/css">
          <xsl:text disable-output-escaping="yes">
            .progressbar .percent.excelent {
              background-color: green;
            }
            #tree .element.good > .name,
            .progressbar .percent.good,
            .demo .good {
              background-color: greenyellow;
            }
            #tree .element.nice > .name,
            .progressbar .percent.nice,
            .demo .nice {
              background-color: yellow;
            }
            #tree .element.bad > .name,
            .progressbar .percent.bad,
            .demo .bad {
              background-color: orange;
            }
            #tree .element.critical > .name,
            .progressbar .percent.critical,
            .demo .critical {
              background-color: orangeRed;
            }
            #tree .element input:checked ~ .children {
              display: block !important;
            }
            #tree .element input ~ .children {
              display: none;
            }

            table, table td {
              border-width: 1px;
              border-style: solid dotted solid dotted;
              border-color: silver;
              border-collapse: collapse;
              padding-left: 0.2em;
              padding-right: 0.2em;
            }
            .progressbar {
              width: 20em;
            }

            .progressbar .percent {
              display: inline-block;
              height: 0.5em;
              vertical-align: middle;
            }
            div.description:nth-of-type(2n+1) {
              background-color: whitesmoke;
            }
            tr:hover {
              background-color: lightyellow;
            }
          </xsl:text>
        </style>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
      </head>
      <body>
        <h1>Coverage report</h1>
        <h2>Summary</h2>
        <table class="summary">
          <xsl:apply-templates select=".|*" mode="summary" />
        </table>

        <h2>Legend</h2>
          <p>Colors correspond to:</p>
          <table class="demo">
            <xsl:call-template name="legend-color">
              <xsl:with-param name="coverage">100</xsl:with-param>
              <xsl:with-param name="description">Full coverage</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="legend-color">
              <xsl:with-param name="coverage">75</xsl:with-param>
              <xsl:with-param name="description">
                <xsl:text>75%-99% coverage, nice</xsl:text>
              </xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="legend-color">
              <xsl:with-param name="coverage">50</xsl:with-param>
              <xsl:with-param name="description">Half the way !</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="legend-color">
              <xsl:with-param name="coverage">0</xsl:with-param>
              <xsl:with-param name="description">Forgot something ?</xsl:with-param>
            </xsl:call-template>
          </table>

        <h2>Tree</h2>
        <!-- Warning IE conditional comment. A warning is displayed if using IE,
           as the tree view has been reported not to work on IE7. ("&lt!" ==  "<") -->
        <xsl:comment>
          <xsl:text>[if IE]>
            &lt;span class="warning" style="background-color: red;font-weight:bold;" >
              This tree representation has been reported not to work on IE.
              Please use a navigator that respect standards.
            &lt;/span>
          &lt;![endif]</xsl:text>
        </xsl:comment>
        <p>Check/Uncheck the checkboxes to fold/unfold.</p>
        <ul class="tree" id="tree">
          <xsl:apply-templates select="." mode="tree" />
        </ul>

        <h2>Description</h2>
        <div class="descriptions">
          <xsl:apply-templates select=".|descendant::*" mode="description" />
        </div>
      </body>
    </html>
  </xsl:template>

  <!--##############
    summary templates
    ##############-->
  <xsl:template mode="summary" match="*">
    <tr>
      <td>
        <a href="#description-{generate-id(.)}">
          <xsl:apply-templates select="." mode="summary-name" />
        </a>
      </td>
      <td><xsl:value-of select="@Coverage" /></td>
      <xsl:apply-templates select="." mode="progress-bar" />
    </tr>
  </xsl:template>

  <xsl:template mode="summary-name" match="/*" >
    <xsl:text>Coverage total average</xsl:text>
  </xsl:template>
  <xsl:template mode="summary-name" match="*">
    <xsl:value-of select="name()" />
  </xsl:template>

  <xsl:template name="legend-color">
    <xsl:param name="coverage" />
    <xsl:param name="description" />
    <tr>
      <td class="coverage">
        <xsl:attribute name="class">
          <xsl:call-template name="choose-quality">
            <xsl:with-param name="coverage">
              <xsl:value-of select="$coverage" />
            </xsl:with-param>
          </xsl:call-template>
        </xsl:attribute>
        <xsl:value-of select="$coverage" />
      </td>
      <td class="coverage">
        <xsl:value-of select="$description" />
      </td>
    </tr>
  </xsl:template>

  <!-- quality coverage templates -->
  <xsl:template name="quality">
    <xsl:call-template name="choose-quality">
      <xsl:with-param name="coverage">
        <xsl:value-of select="number(substring-before(@Coverage,'%'))" />
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="choose-quality">
    <xsl:param name="coverage" />
    <xsl:choose>
      <xsl:when test="$coverage >= 100">excelent</xsl:when>
      <xsl:when test="$coverage >= 75">nice</xsl:when>
      <xsl:when test="$coverage >= 50">bad</xsl:when>
      <xsl:when test="$coverage >= 0">critical</xsl:when>
      <xsl:otherwise />
    </xsl:choose>
  </xsl:template>


  <!--##############
    Tree templates
    ##############-->

  <!-- Ignore the CriterionState nodes and childrens
     as it add a huge number of unimportant info-->
  <xsl:template mode="tree" match="CriterionStates" />

  <xsl:template mode="tree" match="*">
    <li id="tree-{generate-id(.)}">

      <xsl:attribute name="class">
        <xsl:text>element </xsl:text>
        <xsl:call-template name="quality" />
      </xsl:attribute>

      <xsl:apply-templates select="." mode="tree-checkbox" />
      <a class="name description" href="#description-{generate-id(.)}">
        <xsl:value-of select="@Name" />
      </a>

      <xsl:if test="node()">
        <ul class="children"><xsl:apply-templates select="*" mode="tree" /></ul>
      </xsl:if>
    </li>
  </xsl:template>

  <xsl:template mode="tree-checkbox" match="ConfigurableDomain | Criterion">
    <input class="description" type="checkbox" />
  </xsl:template>
  <xsl:template mode="tree-checkbox" match="Domains | Criteria">
    <input class="description" type="checkbox" checked="checked" />
  </xsl:template>
  <xsl:template mode="tree-checkbox" match="*" />

  <!--####################
    Description templates
    ####################-->
  <!-- Ignore the CriterionState nodes and childrens
     as it add a huge number of unimportant info-->
  <xsl:template mode="description" match="CriterionStates|CriterionStates//*" />

  <xsl:template mode="description" match="*">
    <div class="description">
      <h3 id="description-{generate-id(.)}">
        <xsl:value-of select="@Name" />
      </h3>
      <p>
        <xsl:text>Path:</xsl:text>
        <xsl:apply-templates select="ancestor::*|." mode="path" />
      </p>
      <a class="name" href="#tree-{generate-id(.)}">
        <xsl:text>Back to tree</xsl:text>
      </a>
      <h4>Detail</h4>
      <table>
        <xsl:if test="parent::*">
          <tr>
            <td>Type</td>
            <td><xsl:value-of select="name()" /></td>
          </tr>
          <tr>
            <td>Parent</td>
            <td>
              <a class="name" href="#description-{generate-id(..)}">
                <xsl:value-of select="../@Name" />
              </a>
              <xsl:text> (</xsl:text>
              <xsl:value-of select="name(..)" />
              <xsl:text>)</xsl:text>
            </td>
          </tr>
        </xsl:if>
        <xsl:apply-templates select="./@*" mode="description" />
      </table>
      <xsl:if test="node()">
        <h4>Children</h4>
        <table>
          <tr>
            <th>Name</th>
            <th>Type</th>
            <th>Coverage</th>
            <th>Nb use</th>
            <th>Coverage progress bar</th>
          </tr>
          <xsl:apply-templates select="*" mode="description-children" />
        </table>
      </xsl:if>
    </div>
  </xsl:template>

  <xsl:template mode="path" match="*">
    <xsl:text> / </xsl:text>
    <a href="#description-{generate-id(.)}"><xsl:value-of select="@Name" /></a>
  </xsl:template>

  <xsl:template match="@*" mode="description">
    <tr>
      <td><xsl:value-of select="name()" /></td>
      <td><xsl:value-of select="." /></td>
    </tr>
  </xsl:template>


  <!-- Ignore the CriterionState nodes as it add a huge number of unimportant info-->
  <xsl:template mode="description-children" match="CriterionStates" />

  <xsl:template mode="description-children" match="*">
    <tr>
      <td><a class="name" href="#description-{generate-id(.)}">
        <xsl:value-of select="@Name" />
      </a></td>
      <td><xsl:value-of select="name()" /></td>
      <xsl:apply-templates select="./@*" mode="description-children" />
      <xsl:apply-templates select="." mode="progress-bar" />
    </tr>
  </xsl:template>

  <xsl:template match="@Name" mode="description-children" />
  <xsl:template match="@*" mode="description-children">
    <td><xsl:value-of select="." /></td>
  </xsl:template>

  <xsl:template mode="progress-bar" match="*">
    <td class="progressbar">
      <span style="width:{@Coverage}">
        <xsl:attribute name="class">
          <xsl:text>percent </xsl:text>
          <xsl:call-template name="quality" />
        </xsl:attribute>
      </span>
    </td>
  </xsl:template>
</xsl:stylesheet>