<?xml version="1.0" encoding="UTF-8" ?> <!-- Copyright (c) 2009 Exemplics LLC --> <!-- Permission is hereby granted, free of charge, to any person obtaining a copy --> <!-- of this software and associated documentation files (the "Software"), to deal --> <!-- in the Software without restriction, including without limitation the rights --> <!-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --> <!-- copies of the Software, and to permit persons to whom the Software is --> <!-- furnished to do so, subject to the following conditions: --> <!-- The above copyright notice and this permission notice shall be included in --> <!-- all copies or substantial portions of the Software. --> <!-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --> <!-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --> <!-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --> <!-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --> <!-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --> <!-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN --> <!-- THE SOFTWARE. --> <!-- Version 2009.2 --> <!-- Use exclude-result-prefixes so namespaces don't appear in element tags. --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Don't output extra whitespace --> <xsl:strip-space elements="*" /> <xsl:output method="html" encoding="UTF-8" /> <!-- Named template used to output javascript needed to insert elapased time into document tree. --> <xsl:template name="ElapsedMinutes"> <xsl:param name="startTimeString" /> <xsl:param name="endTimeString" /> <script type="text/javascript"> document.write( ElapsedMinutes("<xsl:value-of select="$startTimeString" />", "<xsl:value-of select="$endTimeString" />" ) ); </script> </xsl:template> <!-- Start matching at the root of the XML backup procedure results file. --> <xsl:template match="/"> <!-- $title is used in the title and h1 elements. --> <xsl:variable name="title"> <xsl:value-of select="./BackupProcedure/@ServerShortName" /> <xsl:text> checkpoint </xsl:text> <xsl:value-of select="./BackupProcedure/@CheckpointNumber" /> <xsl:text> </xsl:text> <xsl:value-of select="./BackupProcedure/@BackupType" /> <xsl:text> backup results</xsl:text> </xsl:variable> <html> <head> <title><xsl:value-of select="$title" /></title> <link rel="stylesheet" type="text/css" href="PerforceBackupProcedure.css" /> <!-- Client side javascript functions. --> <!-- XSLT extensions are not needed. --> <script type="text/javascript"><![CDATA[ // Strip leading and trailing whitespace from pre elements. function Load() { var preElements=document.getElementsByTagName("pre"); for (var i=0; i<preElements.length; i++) { preElements[i].firstChild.nodeValue= preElements[i].firstChild.nodeValue.replace(/(^\s+)|(\s+$)/g,''); } } function ElapsedMinutes(startTimeString,endTimeString) { var startMilliseconds = Date.parse(startTimeString); var endMilliseconds = Date.parse(endTimeString); var elapsedMilliseconds = endMilliseconds - startMilliseconds; // Convert milliseconds to minutes and round to two decimal places return (elapsedMilliseconds/60000).toFixed(2); } ]]></script> </head> <body onload="Load()"> <!-- Heading --> <h1><xsl:value-of select="$title" /></h1> <xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match="/BackupProcedure"> <!-- Start time --> <p> <xsl:text>Started </xsl:text> <xsl:value-of select="./Summary/@StartTime" /> </p> <xsl:apply-templates /> </xsl:template> <!-- Output the Steps table. --> <xsl:template match="/BackupProcedure/Steps"> <table> <!-- Output the table section and column headings. --> <tr><td class="SectionHeading" colspan="3">Steps</td></tr> <tr class="ColumnHeadings"> <td class="ResultCode">Result Code</td> <td class="Name">Name</td> <td class="ElapsedMinutes">Elapsed Minutes</td> </tr> <!-- Output the actual steps. --> <xsl:apply-templates /> <tr> <td /> <td /> <!-- Output the total elapsed time in column three. --> <td class="ElapsedMinutes Total"> <xsl:call-template name="ElapsedMinutes"> <xsl:with-param name="startTimeString" select="/BackupProcedure/Summary/@StartTime" /> <xsl:with-param name="endTimeString" select="/BackupProcedure/Summary/@EndTime" /> </xsl:call-template> </td> </tr> </table> <!-- File and directory table. --> <table> <!-- Only output Server Items Archived information if the Backup step ran. --> <xsl:if test="/BackupProcedure/Steps/Step[@Name='Backup']"> <!-- Output the Server Items Archived table section and column headings. --> <tr><td class="SectionHeading" colspan="3">Server Items Archived</td></tr> <tr class="ColumnHeadings"> <td class="Bytes">Bytes</td> <td class="Kind">Kind</td> <td class="Pathname">Pathname</td> </tr> <!-- Output the items that were backed up. --> <xsl:for-each select="/BackupProcedure/Steps/Step[@Name='Backup']/Inputs/*"> <xsl:sort select="@Kind" /> <xsl:sort select="@Pathname" /> <xsl:element name="tr"> <!-- Set table row class to error if this row contains an error. --> <xsl:if test="(name(.) = 'File') and (./@Bytes = '')"> <xsl:attribute name="class">Error</xsl:attribute> </xsl:if> <!-- Some Backup Inputs are Directory elements which do not have Bytes attributes. Do not call format-number unless the Bytes attribute is present. Otherwise, NaN will be output. --> <td class="Bytes"> <xsl:if test="./@Bytes != ''"> <xsl:value-of select="format-number(./@Bytes,'###,###')" /> </xsl:if> </td> <td class="Kind"><xsl:value-of select="./@Kind" /></td> <td class="Pathname"><xsl:value-of select="./@Pathname" /></td> </xsl:element> </xsl:for-each> </xsl:if> <!-- Output the Server Directories table section and column headings. --> <tr><td class="SectionHeading" colspan="3">Server Directories</td></tr> <tr class="ColumnHeadings"> <td class="BytesFree">Bytes Free</td> <td class="Kind">Kind</td> <td class="Pathname">Pathname</td> </tr> <!-- Output the Perforce server root directory and depot versioned file trees. --> <xsl:call-template name="OutputDirectory"> <xsl:with-param name="directory" select="/BackupProcedure/Storage/Directory[@Kind='ServerRoot']" /> </xsl:call-template> <xsl:for-each select="/BackupProcedure/Steps/Step[@Name='Backup']/Inputs/Directory"> <xsl:sort select="@Pathname" /> <xsl:call-template name="OutputDirectory"> <xsl:with-param name="directory" select="." /> </xsl:call-template> </xsl:for-each> <!-- Only output Archive Files information if the Backup step ran. --> <xsl:if test="/BackupProcedure/Steps/Step[@Name='Backup']"> <!-- Output the Archive Files table section and column headings. --> <tr><td class="SectionHeading" colspan="3">Archive Files</td></tr> <tr class="ColumnHeadings"> <td class="Bytes">Bytes</td> <td class="Kind">Kind</td> <td class="Pathname">Pathname</td> </tr> <!-- Output the outputs of the Backup step. --> <xsl:for-each select="/BackupProcedure/Steps/Step[@Name='Backup']/Outputs/*"> <xsl:sort select="@Kind" /> <xsl:sort select="@Pathname" /> <xsl:element name="tr"> <!-- Set table row class to error if this row contains an error. --> <xsl:if test="(name(.) = 'File') and (./@Bytes = '')"> <xsl:attribute name="class">Error</xsl:attribute> </xsl:if> <td class="Bytes"> <xsl:if test="./@Bytes != ''"> <xsl:value-of select="format-number(./@Bytes,'###,###')" /> </xsl:if> </td> <td class="Kind"><xsl:value-of select="./@Kind" /></td> <td class="Pathname"><xsl:value-of select="./@Pathname" /></td> </xsl:element> </xsl:for-each> </xsl:if> <!-- Output the Archive Directories table section and column headings. --> <tr><td class="SectionHeading" colspan="3">Archive Directories</td></tr> <tr class="ColumnHeadings"> <td class="BytesFree">Bytes Free</td> <td class="Kind">Kind</td> <td class="Pathname">Pathname</td> </tr> <!-- Output the BackupDirectory and the LogDirectory. --> <xsl:call-template name="OutputDirectory"> <xsl:with-param name="directory" select="/BackupProcedure/Storage/Directory[@Kind='BackupDirectory']" /> </xsl:call-template> <xsl:call-template name="OutputDirectory"> <xsl:with-param name="directory" select="/BackupProcedure/Storage/Directory[@Kind='LogDirectory']" /> </xsl:call-template> </table> </xsl:template> <!-- Named template used to output directory information. --> <xsl:template name="OutputDirectory"> <xsl:param name="directory" /> <xsl:element name="tr"> <!-- Set table row class to error if this row contains an error. --> <xsl:if test="$directory/@BytesFree = ''"> <xsl:attribute name="class">Error</xsl:attribute> </xsl:if> <td class="BytesFree"> <xsl:if test="$directory/@BytesFree != ''"> <xsl:value-of select="format-number($directory/@BytesFree,'###,###')" /> </xsl:if> </td> <td class="Kind"><xsl:value-of select="$directory/@Kind" /></td> <td class="Pathname"><xsl:value-of select="$directory/@Pathname" /></td> </xsl:element> </xsl:template> <!-- Output each Step --> <xsl:template match="/BackupProcedure/Steps/Step"> <xsl:element name="tr"> <!-- Set table row class to error if this row contains an error. --> <xsl:if test="./Summary/@ResultCode != 0"> <xsl:attribute name="class">Error</xsl:attribute> </xsl:if> <td class="ResultCode"><xsl:value-of select="./Summary/@ResultCode" /></td> <td class="Name"><xsl:value-of select="./@Name" /></td> <td class="ElapsedMinutes"> <xsl:call-template name="ElapsedMinutes"> <xsl:with-param name="startTimeString" select="./Summary/@StartTime" /> <xsl:with-param name="endTimeString" select="./Summary/@EndTime" /> </xsl:call-template> </td> </xsl:element> <!-- Output the ConsoleText of this step if the ResultCode is non-zero (i.e. an error occurred) and the ConsoleText isn't just whitespace. --> <xsl:if test="(./Summary/@ResultCode != 0) and normalize-space(./ConsoleText)"> <tr> <td></td> <td class="ConsoleText" colspan="2"> <pre><xsl:value-of select="./ConsoleText" /></pre> </td> </tr> </xsl:if> </xsl:template> </xsl:stylesheet>
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 7192 | Philip Kania |
Version 2009.2. Added XSLT and CSS style sheets for diplayign XML results as HTML. Added a switch to the scripts to include in the XML results file a link to the XSLT style sheet. |