source: 2015/27/JesseS/JouninTasoloikka/_UpgradeReport_Files/UpgradeReport.xslt @ 6656

Revision 6656, 21.7 KB checked in by jesirkia, 8 years ago (diff)
Line 
1<?xml version="1.0" encoding="utf-8" ?>
2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl='urn:schemas-microsoft-com:xslt'>
3  <xsl:output omit-xml-declaration="yes" />
4
5  <!-- Keys -->
6  <xsl:key name="ProjectKey" match="Event" use="@Project" />
7
8  <!-- String split template -->
9  <xsl:template name="SplitString">
10    <xsl:param name="source"      select="''" />
11    <xsl:param name="separator" select="','" />
12    <xsl:if test="not($source = '' or $separator = '')">
13      <xsl:variable name="head" select="substring-before(concat($source, $separator), $separator)" />
14      <xsl:variable name="tail" select="substring-after($source, $separator)" />
15      <part>
16        <xsl:value-of select="$head"/>
17      </part>
18      <xsl:call-template name="SplitString">
19        <xsl:with-param name="source" select="$tail" />
20        <xsl:with-param name="separator" select="$separator" />
21      </xsl:call-template>
22    </xsl:if>
23  </xsl:template>
24
25  <!-- Intermediate Templates -->
26  <xsl:template match="UpgradeReport" mode="ProjectOverviewXML">
27    <Projects>
28      <xsl:for-each select="Event[generate-id(.) = generate-id(key('ProjectKey', @Project))]">
29        <Project>
30          <xsl:variable name="pNode" select="current()" />
31          <xsl:variable name="errorCount" select="count(../Event[@Project = current()/@Project and @ErrorLevel=2])" />
32          <xsl:variable name="warningCount" select="count(../Event[@Project = current()/@Project and @ErrorLevel=1])" />
33          <xsl:variable name="messageCount" select="count(../Event[@Project = current()/@Project and @ErrorLevel=0])" />
34          <xsl:variable name="pathSplitSeparator">
35            <xsl:text>\</xsl:text>
36          </xsl:variable>
37          <xsl:variable name="projectName">
38            <xsl:choose>
39              <xsl:when test="@Project = ''">Solution</xsl:when>
40              <xsl:otherwise>
41                <xsl:value-of select="@Project"/>
42              </xsl:otherwise>
43            </xsl:choose>
44          </xsl:variable>
45          <xsl:attribute name="IsSolution">
46            <xsl:value-of select="@Project = ''"/>
47          </xsl:attribute>
48          <xsl:attribute name="Project">
49            <xsl:value-of select="$projectName"/>
50          </xsl:attribute>
51          <xsl:attribute name="ProjectDisplayName">
52
53            <xsl:variable name="localProjectName" select="@Project" />
54
55            <!-- Sometimes it is possible to have project name set to a path over a real project name,
56                 we split the string on '\' and if we end up with >1 part in the resulting tokens set
57                 we format the ProjectDisplayName as ..\prior\last -->
58            <xsl:variable name="pathTokens">
59              <xsl:call-template name="SplitString">
60                <xsl:with-param name="source" select="$localProjectName" />
61                <xsl:with-param name="separator" select="$pathSplitSeparator" />
62              </xsl:call-template>
63            </xsl:variable>
64
65            <xsl:choose>
66              <xsl:when test="count(msxsl:node-set($pathTokens)/part) > 1">
67                <xsl:value-of select="concat('..', $pathSplitSeparator, msxsl:node-set($pathTokens)/part[last() - 1], $pathSplitSeparator, msxsl:node-set($pathTokens)/part[last()])"/>
68              </xsl:when>
69              <xsl:otherwise>
70                <xsl:value-of select="$localProjectName"/>
71              </xsl:otherwise>
72            </xsl:choose>
73
74          </xsl:attribute>
75          <xsl:attribute name="ProjectSafeName">
76            <xsl:value-of select="translate($projectName, '\', '-')"/>
77          </xsl:attribute>
78          <xsl:attribute name="Solution">
79            <xsl:value-of select="/UpgradeReport/Properties/Property[@Name='Solution']/@Value"/>
80          </xsl:attribute>
81          <xsl:attribute name="Source">
82            <xsl:value-of select="@Source"/>
83          </xsl:attribute>
84          <xsl:attribute name="Status">
85            <xsl:choose>
86              <xsl:when test="$errorCount > 0">Error</xsl:when>
87              <xsl:when test="$warningCount > 0">Warning</xsl:when>
88              <xsl:otherwise>Success</xsl:otherwise>
89            </xsl:choose>
90          </xsl:attribute>
91          <xsl:attribute name="ErrorCount">
92            <xsl:value-of select="$errorCount" />
93          </xsl:attribute>
94          <xsl:attribute name="WarningCount">
95            <xsl:value-of select="$warningCount" />
96          </xsl:attribute>
97          <xsl:attribute name="MessageCount">
98            <xsl:value-of select="$messageCount" />
99          </xsl:attribute>
100          <xsl:attribute name="TotalCount">
101            <xsl:value-of select="$errorCount + $warningCount + $messageCount"/>
102          </xsl:attribute>
103          <xsl:for-each select="../Event[@Project = $pNode/@Project and @ErrorLevel=3]">
104            <ConversionStatus>
105              <xsl:value-of select="@Description"/>
106            </ConversionStatus>
107          </xsl:for-each>
108          <Messages>
109            <xsl:for-each select="../Event[@Project = $pNode/@Project and @ErrorLevel&lt;3]">
110              <Message>
111                <xsl:attribute name="Level">
112                  <xsl:value-of select="@ErrorLevel" />
113                </xsl:attribute>
114                <xsl:attribute name="Status">
115                  <xsl:choose>
116                    <xsl:when test="@ErrorLevel = 0">Message</xsl:when>
117                    <xsl:when test="@ErrorLevel = 1">Warning</xsl:when>
118                    <xsl:when test="@ErrorLevel = 2">Error</xsl:when>
119                    <xsl:otherwise>Message</xsl:otherwise>
120                  </xsl:choose>
121                </xsl:attribute>
122                <xsl:attribute name="Source">
123                  <xsl:value-of select="@Source"/>
124                </xsl:attribute>
125                <xsl:attribute name="Message">
126                  <xsl:value-of select="@Description"/>
127                </xsl:attribute>
128              </Message>
129            </xsl:for-each>
130          </Messages>
131        </Project>
132      </xsl:for-each>
133    </Projects>
134  </xsl:template>
135
136
137
138  <!-- Project Overview template -->
139  <xsl:template match="Projects" mode="ProjectOverview">
140
141    <table>
142      <tr>
143        <th></th>
144        <th _locID="ProjectTableHeader">Project</th>
145        <th _locID="PathTableHeader">Path</th>
146        <th _locID="ErrorsTableHeader">Errors</th>
147        <th _locID="WarningsTableHeader">Warnings</th>
148        <th _locID="MessagesTableHeader">Messages</th>
149      </tr>
150
151      <xsl:for-each select="Project">
152
153        <xsl:sort select="@ErrorCount" order="descending" />
154        <xsl:sort select="@WarningCount" order="descending" />
155        <!-- Always make solution last within a group -->
156        <xsl:sort select="@IsSolution" order="ascending" />
157        <xsl:sort select="@ProjectSafeName" order="ascending" />
158
159        <tr>
160          <td>
161            <img width="16" height="16">
162              <xsl:attribute name="src">
163                <xsl:choose>
164                  <xsl:when test="@Status = 'Error'">_UpgradeReport_Files\UpgradeReport_Error.png</xsl:when>
165                  <xsl:when test="@Status = 'Warning'">_UpgradeReport_Files\UpgradeReport_Warning.png</xsl:when>
166                  <xsl:when test="@Status = 'Success'">_UpgradeReport_Files\UpgradeReport_Success.png</xsl:when>
167                </xsl:choose>
168              </xsl:attribute>
169              <xsl:attribute name="alt">
170                <xsl:value-of select="@Status" />
171              </xsl:attribute>
172            </img>
173          </td>
174          <td>
175            <strong>
176              <a>
177                <xsl:attribute name="href">
178                  <xsl:value-of select="concat('#', @ProjectSafeName)"/>
179                </xsl:attribute>
180                <xsl:choose>
181                  <xsl:when test="@ProjectDisplayName = ''">
182                    <span _locID="OverviewSolutionSpan">Solution</span>
183                  </xsl:when>
184                  <xsl:otherwise>
185                    <xsl:value-of select="@ProjectDisplayName" />
186                  </xsl:otherwise>
187                </xsl:choose>
188              </a>
189            </strong>
190          </td>
191          <td>
192            <xsl:value-of select="@Source" />
193          </td>
194          <td class="textCentered">
195            <a>
196              <xsl:if test="@ErrorCount > 0">
197                <xsl:attribute name="href">
198                  <xsl:value-of select="concat('#', @ProjectSafeName, 'Error')"/>
199                </xsl:attribute>
200              </xsl:if>
201              <xsl:value-of select="@ErrorCount" />
202            </a>
203          </td>
204          <td class="textCentered">
205            <a>
206              <xsl:if test="@WarningCount > 0">
207                <xsl:attribute name="href">
208                  <xsl:value-of select="concat('#', @ProjectSafeName, 'Warning')"/>
209                </xsl:attribute>
210              </xsl:if>
211              <xsl:value-of select="@WarningCount" />
212            </a>
213          </td>
214          <td class="textCentered">
215            <a href="#">
216              <xsl:if test="@MessageCount > 0">
217                <xsl:attribute name="onclick">
218                  <xsl:variable name="apos">
219                    <xsl:text>'</xsl:text>
220                  </xsl:variable>
221                  <xsl:variable name="JS" select="concat('ScrollToFirstVisibleMessage(', $apos, @ProjectSafeName, $apos, ')')" />
222                  <xsl:value-of select="concat($JS, '; return false;')"/>
223                </xsl:attribute>
224              </xsl:if>
225              <xsl:value-of select="@MessageCount" />
226            </a>
227          </td>
228        </tr>
229      </xsl:for-each>
230    </table>
231  </xsl:template>
232
233  <!-- Show messages row -->
234  <xsl:template match="Project" mode="ProjectShowMessages">
235    <tr>
236      <xsl:attribute name="name">
237        <xsl:value-of select="concat('MessageRowHeaderShow', @ProjectSafeName)"/>
238      </xsl:attribute>
239      <td>
240        <img width="16" height="16" src="_UpgradeReport_Files\UpgradeReport_Information.png" />
241      </td>
242      <td class="messageCell">
243        <xsl:variable name="apos">
244          <xsl:text>'</xsl:text>
245        </xsl:variable>
246        <xsl:variable name="toggleRowsJS" select="concat('ToggleMessageVisibility(', $apos, @ProjectSafeName, $apos, ')')" />
247
248        <a _locID="ShowAdditionalMessages" href="#">
249          <xsl:attribute name="name">
250            <xsl:value-of select="concat(@ProjectSafeName, 'Message')"/>
251          </xsl:attribute>
252          <xsl:attribute name="onclick">
253            <xsl:value-of select="concat($toggleRowsJS, '; return false;')"/>
254          </xsl:attribute>
255          Show <xsl:value-of select="@MessageCount" /> additional messages
256        </a>
257      </td>
258    </tr>
259  </xsl:template>
260
261  <!-- Hide messages row -->
262  <xsl:template match="Project" mode="ProjectHideMessages">
263    <tr style="display: none">
264      <xsl:attribute name="name">
265        <xsl:value-of select="concat('MessageRowHeaderHide', @ProjectSafeName)"/>
266      </xsl:attribute>
267      <td>
268        <img width="16" height="16" src="_UpgradeReport_Files\UpgradeReport_Information.png" />
269      </td>
270      <td class="messageCell">
271        <xsl:variable name="apos">
272          <xsl:text>'</xsl:text>
273        </xsl:variable>
274        <xsl:variable name="toggleRowsJS" select="concat('ToggleMessageVisibility(', $apos, @ProjectSafeName, $apos, ')')" />
275
276        <a _locID="HideAdditionalMessages" href="#">
277          <xsl:attribute name="name">
278            <xsl:value-of select="concat(@ProjectSafeName, 'Message')"/>
279          </xsl:attribute>
280          <xsl:attribute name="onclick">
281            <xsl:value-of select="concat($toggleRowsJS, '; return false;')"/>
282          </xsl:attribute>
283          Hide <xsl:value-of select="@MessageCount" /> additional messages
284        </a>
285      </td>
286    </tr>
287  </xsl:template>
288
289  <!-- Message row templates -->
290  <xsl:template match="Message">
291    <tr>
292      <xsl:attribute name="name">
293        <xsl:value-of select="concat(@Status, 'RowClass', ../../@ProjectSafeName)"/>
294      </xsl:attribute>
295
296      <xsl:if test="@Level = 0">
297        <xsl:attribute name="style">display: none</xsl:attribute>
298      </xsl:if>
299      <td>
300        <a>
301          <xsl:attribute name="name">
302            <xsl:value-of select="concat(../../@ProjectSafeName, @Status)"/>
303          </xsl:attribute>
304        </a>
305        <img width="16" height="16">
306          <xsl:attribute name="src">
307            <xsl:choose>
308              <xsl:when test="@Status = 'Error'">_UpgradeReport_Files\UpgradeReport_Error.png</xsl:when>
309              <xsl:when test="@Status = 'Warning'">_UpgradeReport_Files\UpgradeReport_Warning.png</xsl:when>
310              <xsl:when test="@Status = 'Message'">_UpgradeReport_Files\UpgradeReport_Information.png</xsl:when>
311            </xsl:choose>
312          </xsl:attribute>
313          <xsl:attribute name="alt">
314            <xsl:value-of select="@Status" />
315          </xsl:attribute>
316        </img>
317      </td>
318      <td class="messageCell">
319        <strong>
320          <xsl:value-of select="@Source"/>:
321        </strong>
322        <span>
323          <xsl:value-of select="@Message"/>
324        </span>
325      </td>
326    </tr>
327  </xsl:template>
328
329  <!-- Project Details Template -->
330  <xsl:template match="Projects" mode="ProjectDetails">
331
332    <xsl:for-each select="Project">
333      <xsl:sort select="@ErrorCount" order="descending" />
334      <xsl:sort select="@WarningCount" order="descending" />
335      <!-- Always make solution last within a group -->
336      <xsl:sort select="@IsSolution" order="ascending" />
337      <xsl:sort select="@ProjectSafeName" order="ascending" />
338
339      <a>
340        <xsl:attribute name="name">
341          <xsl:value-of select="@ProjectSafeName"/>
342        </xsl:attribute>
343      </a>
344      <xsl:choose>
345        <xsl:when test="@ProjectDisplayName = ''">
346          <h3 _locID="ProjectDisplayNameHeader">Solution</h3>
347        </xsl:when>
348        <xsl:otherwise>
349          <h3>
350            <xsl:value-of select="@ProjectDisplayName"/>
351          </h3>
352        </xsl:otherwise>
353      </xsl:choose>
354
355      <table>
356        <tr>
357          <xsl:attribute name="id">
358            <xsl:value-of select="concat(@ProjectSafeName, 'HeaderRow')"/>
359          </xsl:attribute>
360          <th></th>
361          <th class="messageCell" _locID="MessageTableHeader">Message</th>
362        </tr>
363
364        <!-- Errors and warnings -->
365        <xsl:for-each select="Messages/Message[@Level &gt; 0]">
366          <xsl:sort select="@Level" order="descending" />
367          <xsl:apply-templates select="." />
368        </xsl:for-each>
369
370        <xsl:if test="@MessageCount > 0">
371          <xsl:apply-templates select="." mode="ProjectShowMessages" />
372        </xsl:if>
373
374        <!-- Messages -->
375        <xsl:for-each select="Messages/Message[@Level = 0]">
376          <xsl:apply-templates select="." />
377        </xsl:for-each>
378
379        <xsl:choose>
380          <!-- Additional row as a 'place holder' for 'Show/Hide' additional messages -->
381          <xsl:when test="@MessageCount > 0">
382            <xsl:apply-templates select="." mode="ProjectHideMessages" />
383          </xsl:when>
384          <!-- No messages at all, show blank row -->
385          <xsl:when test="@TotalCount = 0">
386            <tr>
387              <td>
388                <img width="16" height="16" src="_UpgradeReport_Files\UpgradeReport_Information.png" />
389              </td>
390              <xsl:choose>
391                <xsl:when test="@ProjectDisplayName = ''">
392                  <td class="messageCell" _locID="NoMessagesRow2">
393                    Solution logged no messages.
394                  </td>
395                </xsl:when>
396                <xsl:otherwise>
397                  <td class="messageCell" _locID="NoMessagesRow">
398                    <xsl:value-of select="@ProjectDisplayName" /> logged no messages.
399                  </td>
400                </xsl:otherwise>
401              </xsl:choose>
402            </tr>
403          </xsl:when>
404        </xsl:choose>
405      </table>
406    </xsl:for-each>
407  </xsl:template>
408
409  <!-- Document, matches "UpgradeReport" -->
410  <xsl:template match="UpgradeReport">
411    <!-- Output doc type the 'Mark of the web' which disabled prompting to run JavaScript from local HTML Files in IE -->
412    <!-- NOTE: The whitespace around the 'Mark of the web' is important it must be exact -->
413    <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE html>
414<!-- saved from url=(0014)about:internet -->
415]]>
416    </xsl:text>
417    <html>
418      <head>
419        <meta content="en-us" http-equiv="Content-Language" />
420        <meta content="text/html; charset=utf-16" http-equiv="Content-Type" />
421        <link type="text/css" rel="stylesheet" href="_UpgradeReport_Files\UpgradeReport.css" />
422        <title _locID="ConversionReport0">
423          Migration Report
424        </title>
425
426        <script type="text/javascript" language="javascript">
427          <xsl:text disable-output-escaping="yes">
428          <![CDATA[
429         
430            // Startup
431            // Hook up the the loaded event for the document/window, to linkify the document content
432            var startupFunction = function() { linkifyElement("messages"); };
433           
434            if(window.attachEvent)
435            {
436              window.attachEvent('onload', startupFunction);
437            }
438            else if (window.addEventListener)
439            {
440              window.addEventListener('load', startupFunction, false);
441            }
442            else
443            {
444              document.addEventListener('load', startupFunction, false);
445            }
446           
447            // Toggles the visibility of table rows with the specified name
448            function toggleTableRowsByName(name)
449            {
450               var allRows = document.getElementsByTagName('tr');
451               for (i=0; i < allRows.length; i++)
452               {
453                  var currentName = allRows[i].getAttribute('name');
454                  if(!!currentName && currentName.indexOf(name) == 0)
455                  {
456                      var isVisible = allRows[i].style.display == '';
457                      isVisible ? allRows[i].style.display = 'none' : allRows[i].style.display = '';
458                  }
459               }
460            }
461           
462            function scrollToFirstVisibleRow(name)
463            {
464               var allRows = document.getElementsByTagName('tr');
465               for (i=0; i < allRows.length; i++)
466               {
467                  var currentName = allRows[i].getAttribute('name');
468                  var isVisible = allRows[i].style.display == '';
469                  if(!!currentName && currentName.indexOf(name) == 0 && isVisible)
470                  {
471                     allRows[i].scrollIntoView(true);
472                     return true;
473                  }
474               }
475               
476               return false;
477            }
478           
479            // Linkifies the specified text content, replaces candidate links with html links
480            function linkify(text)
481            {
482                 if(!text || 0 === text.length)
483                 {
484                     return text;
485                 }
486
487                 // Find http, https and ftp links and replace them with hyper links
488                 var urlLink = /(http|https|ftp)\:\/\/[a-zA-Z0-9\-\.]+(:[a-zA-Z0-9]*)?\/?([a-zA-Z0-9\-\._\?\,\/\\\+&%\$#\=~;\{\}])*/gi;
489                 
490                 return text.replace(urlLink, '<a href="$&">$&</a>') ;
491            }
492           
493            // Linkifies the specified element by ID
494            function linkifyElement(id)
495            {
496                var element = document.getElementById(id);
497                if(!!element)
498                {
499                  element.innerHTML = linkify(element.innerHTML);
500                }
501            }
502           
503            function ToggleMessageVisibility(projectName)
504            {
505              if(!projectName || 0 === projectName.length)
506              {
507                return;
508              }
509             
510              toggleTableRowsByName("MessageRowClass" + projectName);
511              toggleTableRowsByName('MessageRowHeaderShow' + projectName);
512              toggleTableRowsByName('MessageRowHeaderHide' + projectName);
513            }
514           
515            function ScrollToFirstVisibleMessage(projectName)
516            {
517              if(!projectName || 0 === projectName.length)
518              {
519                return;
520              }
521             
522              // First try the 'Show messages' row
523              if(!scrollToFirstVisibleRow('MessageRowHeaderShow' + projectName))
524              {
525                // Failed to find a visible row for 'Show messages', try an actual message row
526                scrollToFirstVisibleRow('MessageRowClass' + projectName);
527              }
528            }
529          ]]>
530        </xsl:text>
531        </script>
532      </head>
533      <body>
534        <h1 _locID="ConversionReport">
535          Migration Report - <xsl:value-of select="Properties/Property[@Name='Solution']/@Value"/>
536        </h1>
537
538        <div id="content">
539          <h2 _locID="OverviewTitle">Overview</h2>
540          <xsl:variable name="projectOverview">
541            <xsl:apply-templates select="self::node()" mode="ProjectOverviewXML" />
542          </xsl:variable>
543
544          <div id="overview">
545            <xsl:apply-templates select="msxsl:node-set($projectOverview)/*" mode="ProjectOverview" />
546          </div>
547
548          <h2 _locID="SolutionAndProjectsTitle">Solution and projects</h2>
549
550          <div id="messages">
551            <xsl:apply-templates select="msxsl:node-set($projectOverview)/*" mode="ProjectDetails" />
552          </div>
553        </div>
554      </body>
555    </html>
556  </xsl:template>
557
558</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.