rmat XML

Revision History:

01-19-2016  marcguy      initial version
-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" version="1.0" indent="no" omit-xml-declaration="no"/>
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
PA<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright (c) 2014  Microsoft Corporation

Module Name:

wlanreport-stylesheet.xsl

Abstract:

Stylesheet defining how the xml report is
transformed into the html report

Revision History:

09-28-2014  ryanwood      initial version
02-01-2015  ryanwood      add in rendering for custom commands
-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template name="css">
        <style type="text/css">
          body {
          margin: 0;
          padding: 0;
          background-color: #EFEFEF;
          font-family: "segoe ui light", "segoe ui";
          letter-spacing: 0.03em;
          }

          table {
          border-collapse: collapse;
          }

          th {
          border: 1px solid #222;
          text-align: center;
          }

          tr {
          height: 1.5em;
          border: 1px solid #222;
          }

          td {
          border: 1px solid #222;
          }

          #top-btn {
          position: fixed;
          padding: 5px;
          border: 2px solid #333;
          cursor: pointer;
          }
          #top-btn p {
          margin: 0;
          }

          #report-wrapper {
          width: 1000px;
          margin: 0 auto;
          }

          #session-graph-wrapper {
          background-color: #1F1F1F;
          outline: 2px solid #AAA;
          }

          #session-graph {
          cursor: pointer;
          }

          #graph-event-info {
          float: left;
          width: 500px;
          height: 170px;
          color: #DDD;
          padding: 0px 30px 0px 20px;
          }
          #graph-event-info h4 {
          margin: 0px 0px 10px 0px;
          }

          #event-info {
          margin: 0;
          height: 135px overflow: scroll;
          }

          #sysinfo {
          margin: 0px 0px 30px 0px;
          }
          #sysinfo p {
          margin: 0;
          padding: 0;
          }

          #report-info p {
          margin: 0;
          padding: 0;
          }

          #disconnect-status tr {
          border: 1px solid #222;
          }

          #disconnect-status td {
          border: 1px solid #222;
          }

          #disconnect-status .status {
          width: 300px;
          padding-top: 0px;
          }

          #disconnect-reasons .reason {
          width: 800px;
          padding-top: 0;
          }

          .count {
          width: 75px;
          text-align: center;
          }

          .graph-background {
          position: absolute;
          z-index: -1;
          height: 1.5em;
          margin: -1px;
          background-color: rgb(171,168,244);
          }
          .graph-background.success {
          background-color: rgb(108, 216, 108);
          }

          .graph-background.failure {
          background-color: rgb(216, 108, 108);
          }

          .graph-background.warning {
          background-color: rgb(216, 216, 108);
          }

          #session-durations {
          border-left: 1px solid #222;
          overflow: hidden;
          }

          #duration-labels {
          text-align: center;
          }

          #duration-graph {
          height: 550px;
          border: none;
          }
          #duration-graph td {
          width: 80px;
          padding: 0px 2px 0px 2px;
          vertical-align: top;
          position: relative;
          border: none;
          }

          .duration-bar {
          width: 80px;
          position: absolute;
          }

          .bar-label {
          width: 80px;
          position: absolute;
          text-align: center;
          font-weight: bold;
          }

          .bar-background {
          background-color: rgb(171,168,244);
          display: block;
          width: 100%;
          height: 100%;
          outline: 1px solid #222;
          }

          .session {
          background-color: #FFF;
          margin: 0px 0px 20px 0px;
          padding: 10px;
          border: 2px solid #666;
          }
          .session p {
          margin: 0.2em;
          }

          .session table {
          width: 100%;
          }

          .session .event-header {
          width: 75px;
          }

          .session .time-header {
          width: 180px;
          }

          .session .message-header {
          width: auto;
          }

          .successful {
          background-color: #1BEB00;
          }

          .warning {
          background-color: #EBEB00;
          }

          .failed {
          background-color: #F00;
          }

          .info {
          background-color: #E2E2E2;
          }

          .message {
          width: 700px;
          height: 1.5em;
          overflow: hidden;
          white-space: pre;
          text-overflow: ellipsis;
          }
          .message.show {
          height: auto;
          overflow: auto;
          white-space: normal;
          }

          .message .expand-btn {
          cursor: pointer;
          }

          .error {
          background-color: rgb(255,178,178);
          font-weight: bold;
          }

          .ndis.sleep {
          background-color: #AF9AE4;
          }

          .ndis.wake {
          background-color: #E49AEF;
          }

          .wlan {
          background-color: #FFF;
          }
          .wlan.connect {
          background-color: #9AE4A6;
          }

          .wlan.disconnect {
          background-color: #F5BE9C;
          }

          .ncsi.internet {
          background-color: #9CCAF5;
          }

          .ncsi.local {
          background-color: #F1F59C;
          }

          .ncsi.none {
          background-color: #F59C9C;
          }
		  
          .wcm {
          background-color: #F0FFFF;
          }
		  
          .eap {
          background-color: #FFFFF0;
          }
		  
          .glow {
          font-weight: bold;
          outline: 3px solid #000000;
          }
		  
          #commands-output {
          margin: 0px 0px 30px 0px;
          }
          .command-output {
          background-color: #000;
          color: #C0C0C0;
          padding: 5px;
          outline: 5px solid #BBB;
          }
        </style>
    </xsl:template>
    
    <xsl:template name="js">
        var wlanReport = ( function()
        {
            var wlanReport = {},

            pointRadius = 8,
            eventOffset = 50,
            wlanYOffset = 0,
            ncsiYOffset = 100,
            ndisYOffset = 200,
            eventRenderInfo,
            boundRenderInfo,
            wlanBounds = [],
            connectivityBounds = [],
            powerBounds = [],

            bindToggleMessageBtns,
            toggleMessage,
            timeToXCoord,
            findNewestEvent,
            calculateEventCoordinates,
            findwlanBounds,
            findConnectivityBounds,
            findPowerBounds,
            drawEvents,
            drawPoint,
            drawSessionBounds,
            drawBound,
            drawAxis,
            drawEventRegionLabels,
            drawLegend,
            drawLegendLabel,
            drawSessionGraph,
            eventClickHandler,
            eventMouseMoveHandler,
            calculateSessionDuration,
            getSnapshotAtXY,
            getSessionAtXY,
            convertSnapshotTimes,
            convertFileTimeToUnixTime,
            fixCommandOutputFormatting,
			checkForEmptyReport,
            bindTopBtn;

            eventRenderInfo = {
                'Connect':   {'label':'C', 'color':'#9AE4A6'},
                'Disconnect':{'label':'D', 'color':'#F5BE9C'},
                'Sleep':     {'label':'S', 'color':'#AF9AE4'},
                'CS-Sleep':  {'label':'S', 'color':'#AF9AE4'},
                'Wake':      {'label':'W', 'color':'#E49AEF'},
                'CS-Wake':   {'label':'W', 'color':'#E49AEF'},
                'Internet':  {'label':'I', 'color':'#9CCAF5'},
                'Local':     {'label':'L', 'color':'#F1F59C'},
                'None':      {'label':'N', 'color':'#F59C9C'},
                'Error':     {'label':'X', 'color':'#FF0000'}
            };

            boundRenderInfo = {
                'Connected':       {'fill':'rgba(0,210,0,0.3)','stroke':'rgba(0,210,0,0.8)', 'lineWidth':'3'},
                'Power':           {'fill':'rgba(0,0,0,0.95)', 'stroke':'rgba(20,20,20,1.0)','lineWidth':'1'},
                'ConnectedStandby':{'fill':'rgba(0,135,0,0.3)','stroke':'rgba(0,100,0,0.95)','lineWidth':'1'}
            };

            bindToggleMessageBtns = function()
            {
                var divElements,
                    expandBtn,
                    i;

                divElements = document.getElementsByTagName('div');

                for( i = 0; i &lt; divElements.length; i++ ) {
                    if( divElements[i].className === 'message' ) {
                        expandBtn = divElements[i].firstChild;
                        expandBtn.addEventListener('click', toggleMessage(expandBtn), false);
                    }
                }
            };

            toggleMessage = function(btn)
            {
                return function() {
                    var message = btn.parentNode;

                    if(message.className === "message")
                    {
                        message.className = "message show";
                        btn.innerHTML = "[&#8210;]"; //A digit width hyphen. This way the button doesn't shrink (by much)
                    }
                    else
                    {
                        message.className = "message";
                        btn.innerHTML = "[+]";
                    }
                }
            };
            
            // Calculate the X coordinate for the snapshot based on the time it
            // occured relative to the 48 hours displayed on the graph.
            timeToXCoord = function(startTimeStr, snapshotTimeStr, width)
            {
                var twoDaysInMS  = (1000 * 60 * 60 * 24) * 2,
                    startTime    = parseInt(startTimeStr, 10),
                    snapshotTime = parseInt(snapshotTimeStr, 10),
                    endTime = startTime - twoDaysInMS,
                    xPosRatio    = 0;

                xPosRatio = (snapshotTime - startTime) / (endTime - startTime);

                return (width - (xPosRatio * width));
            };

            calculateEventCoordinates = function(canvas)
            {
                var width,
                    height,
                    xOffset  = 10,
                    yOffset  = 0,
                    xPos     = 0,
                    yPos     = 0,
                    lastXPos = [],
                    minXDiff = 2 * pointRadius, //The min difference between points to prevent them from overlapping
                    startTime,
                    i;

                if(snapshots.length === 0) {
                    return;
                }

                width = canvas.width;
                height = canvas.height;

                lastXPos[wlanYOffset] = -1;
                lastXPos[ndisYOffset] = -1;
                lastXPos[ncsiYOffset] = -1;

                startTime = findNewestEvent();

                for(i = 0; i &lt; snapshots.length; i++)
                {
                    if(snapshots[i].type === 'Connect') {
                        yOffset = wlanYOffset;
                    } else if(snapshots[i].type === 'Disconnect') {
                        yOffset = wlanYOffset;
                    } else if(snapshots[i].type === 'Error') {
                        yOffset = wlanYOffset;
                    } else if(snapshots[i].type === 'Wake' || snapshots[i].type === 'CS-Wake') {
                        yOffset = ndisYOffset;
                    } else if(snapshots[i].type === 'Sleep' || snapshots[i].type === 'CS-Sleep') {
                        yOffset = ndisYOffset;
                    } else {
                        yOffset = ncsiYOffset;
                    }

                    xPos = timeToXCoord(startTime, snapshots[i].time, width) - xOffset;
                    if(lastXPos[yOffset] >= 0 &amp;&amp; (lastXPos[yOffset]) - xPos &lt; minXDiff)
                    {
                        // Keep track of the offset we are adding to events to make sure that events
                        // remain in chronological order across their different y-axis channels (wlan,ndis,ncsi)
                        xOffset += (minXDiff - (lastXPos[yOffset] - xPos));
                        xPos = lastXPos[yOffset] - minXDiff;
                    }
                    
                    yPos = eventOffset + yOffset;
                    snapshots[i].x = xPos;
                    snapshots[i].y = yPos;

                    lastXPos[yOffset] = xPos;

                    // If the xPos is greater than the width of the canvas
                    // stop calculating cordinates since they won't fit anyways.
                    if (xPos > width) {
                        snapshots = snapshots.slice(0, i); //Discard the points that don't fit
                        break;
                    }
                }
            };

            // Unfortunatly the newest event is not always the first event in the list,
            // so we have to do a search for the newest event
            findNewestEvent = function()
            {
                var startTime = 0,
                    i;

                for(i = 0; i &lt; snapshots.length; i++) {
                    startTime = Math.max(startTime, snapshots[i].time);
                }

                return startTime;
            };

            drawEvents = function(canvas)
            {
                var graph,
                pointLabel,
                snapshot,
                style,
                i;

                graph = canvas.getContext('2d');

                if(snapshots.length === 0){
                    graph.font = "18px sans-serif";
                    graph.fillStyle = "#EFEFEF";
                    graph.textAlign = "center";
                    graph.fillText("No events from the last 48 hours to display", canvas.width/2, canvas.height/2);
                    return;
                }

                graph.strokeStyle = "#111";
                graph.lineWidth = 1;

                for( i = 0; i &lt; snapshots.length; i++)
                {
                    snapshot = snapshots[i];
                    
                    if(snapshot.error !== "0") {
                      style = eventRenderInfo["Error"];
                    } else {
                      style = eventRenderInfo[snapshot.type];
                    }
                
                    if( style === undefined) {
                        continue;
                    }
                
                    graph.fillStyle = style.color;
                    pointLabel = style.label;

                    drawPoint(graph, snapshot.x, snapshot.y, pointLabel);

                }
            };

            drawPoint = function(graph, x, y, label)
            {
                graph.font = "10px sans-serif";
                graph.textAlign = "center";

                graph.beginPath();
                graph.arc( x, y, pointRadius, 0, 2 * Math.PI, false);
                graph.fill();
                graph.stroke();

                graph.fillStyle = "#222";
                graph.fillText(label, x, y + (pointRadius/2));
            };

            findwlanBounds = function()
            {
                var connectEvent    = null,
                    disconnectEvent = null,
                    isConnected     = false,
                    currentEvent,
                    type,
                    boundType,
                    i;

                // Snapshots only include the state from the last 48 hours.
                // In order to properly draw session bounds we need to know
                // the state from when the 48 hours started. i.e. was a session
                // in progress already when the 48 section began. To fnd this out
                // look to see if the first wlan event is a disconnect or a connect.
                for(i = snapshots.length - 1; i &gt;= 0; i-- )
                {
                    if( snapshots[i].type === 'Disconnect' ) {
                        isConnected = true;
                        break;
                    } else if (snapshots[i].type === 'Connect'){
                        isConnected = false;
                        break;
                    }
                }

                // If we start in a connected state draw a bound from the left side
                // of the graph to the first wlan/ndis event
                if( isConnected ) {
                    for(i = snapshots.length - 1; i &gt;= 0; i-- )
                    {
                        type = snapshots[i].type;
                        
                        if(type === 'Wake' || type === 'CS-Wake' )
                        {
                            boundType = type === 'Wake' ? 'Sleep' : 'CS-Sleep';
                            
                            powerBounds.push({'type':boundType, 'sleepEvent':snapshots[i], 'wakeEvent':snapshots[i], 'x':0, 'y':snapshots[i].y,
                                'width':snapshots[i].x, 'height':200});
                                break;
                        }
                        else if(type === 'Disconnect')
                        {
                            wlanBounds.push({'connectEvent':snapshots[i], 'disconnectEvent':snapshots[i], 'x':0, 'y': wlanYOffset + eventOffset,
                                'width':snapshots[i].x, 'height':200});
                                break;
                        }
                    }
                }
                
                // Loop through all of the events finding pairs of events to draw a box between
                // indicating the start and stop of a particular wlan state. Current pairs include
                //
                // Connect->Disconnect/Error/Sleep/CS-Sleep
                // Wake->Disconnect/Error/Sleep/CS-Sleep (if previously connected)
                //
                for(i = snapshots.length - 1; i &gt;= 0; i-- )
                {
                    currentEvent = snapshots[i];
                    type = currentEvent.type;

                    if ( type === 'Internet' || type === 'Local' || type == 'None')
                    {
                        continue;
                    }

                    if( type === 'Connect' )
                    {
                        if (connectEvent === null)
                        {
                            connectEvent = snapshots[i];
                        }
                        isConnected = true;
                    }
                    else if( type === 'Disconnect' || type === 'Sleep' || type === 'CS-Sleep')
                    {
                        disconnectEvent = snapshots[i];

                        // If we are stopping the session because of the Sleep, consider the
                        // session to still be connected since we will likely do a fast reconnect
                        // on wake meaning we will not see a new connect event
                        if( type !== 'Sleep' &amp;&amp; type !== 'CS-Sleep')
                        {
                            isConnected = false;
                        }

                        // If we have a connect event and a disconnect event, have the session bounds be a box connecting them
                        if(connectEvent !== null &amp;&amp; disconnectEvent !== null )
                        {
                            wlanBounds.push({'connectEvent':connectEvent, 'disconnectEvent':disconnectEvent, 'x':connectEvent.x, 'y': wlanYOffset + eventOffset,
                                'width':disconnectEvent.x - connectEvent.x, 'height':200});
                        }

                        // If we only have a disconnect event, and it is the first connection event,
                        // Draw a session bounds from the left end of the graph to the disconnect
                        if( connectEvent === null &amp;&amp; wlanBounds.length === 0 )
                        {
                            wlanBounds.push({'connectEvent':null, 'disconnectEvent':disconnectEvent, 'x':0, 'y':wlanYOffset + eventOffset,
                                'width':disconnectEvent.x, 'height':200});
                        }

                        connectEvent = null;
                        disconnectEvent = null;
                    }
                    else if( type === 'Wake' || type === 'CS-Wake' )
                    {
                        if(isConnected &amp;&amp; connectEvent === null)
                        {
                            connectEvent = snapshots[i];
                        }
                    }
                }

                // If there is a current active session with no disconnect draw its bound
                // The bound will be from the connect to beyond the end of the graph
                if( connectEvent !== null &amp;&amp; disconnectEvent === null)
                {
                    wlanBounds.push({'connectEvent':connectEvent, 'disconnectEvent':null, 'x':connectEvent.x, 'y':wlanYOffset + eventOffset,
                        'width':1000, 'height':200});
                }
            };

            findConnectivityBounds = function()
            {
                var connectivityStart    = null,
                    connectivityEnd      = null,
                    isConnectedToNetwork = false,
                    i;

                for(i = snapshots.length - 1; i &gt;= 0; i-- )
                {
                    if (snapshots[i].type === 'Connect')
                    {
                        isConnectedToNetwork = true;
                    }
                    else if (snapshots[i].type === 'Disconnect' || snapshots[i].type === 'Sleep' || snapshots[i].type === 'Error')
                    {
                        connectivityEnd = snapshots[i];

                        // Draw the bounds of the last capability from when it
                        // started to when the disconnect event happened
                        if (connectivityStart !== null) {
                            connectivityBounds.push({'startEvent':connectivityStart, 'endEvent':connectivityEnd, 'x':connectivityStart.x, 'y':connectivityStart.y,
                                'width':connectivityEnd.x - connectivityStart.x, 'height':2*pointRadius});
                        }

                        if (snapshots[i].type === 'Disconnect') {
                            isConnectedToNetwork = false;
                        }

                        connectivityStart = null;
                        connectivityEnd = null;
                    }
                    else if(snapshots[i].type === 'Internet' || snapshots[i].type === 'Local' || snapshots[i].type === 'None')
                    {
                        // Don't draw bounds between capability events
                        // that are not part of a session
                        if( !isConnectedToNetwork )
                        {
                            continue;
                        }

                        if( connectivityStart == null )
                        {
                            connectivityStart = snapshots[i];
                        }
                        else
                        {
                            connectivityEnd = snapshots[i];

                            connectivityBounds.push({'startEvent':connectivityStart, 'endEvent':connectivityEnd, 'x':connectivityStart.x, 'y':connectivityStart.y,
                                'width':connectivityEnd.x - connectivityStart.x, 'height':2*pointRadius});

                            connectivityStart = connectivityEnd;
                            connectivityEnd = null;
                        }
                    }
                    else if ( snapshots[i].type === 'Disconnect' &amp;&amp; connectivityStart !== null )
                    {
                        // Do not draw connectivity bounds that span from one session to another.
                        // On disconnect there is an implicit capability None where the current
                        // capability would end.
                        connectivityBounds.push({'startEvent':connectivityStart, 'endEvent':snapshots[i], 'x':connectivityStart.x, 'y':connectivityStart.y,
                            'width':snapshots[i].x - connectivityStart.x, 'height':2*pointRadius});

                        connectivityStart = null;
                        connectivityEnd = null;
                    }
                }

                // If the last connectivity event started a bounds, creat a region
                // from it to the edge of the graph
                if(connectivityStart)
                {
                    connectivityBounds.push({'startEvent':connectivityStart, 'endEvent':null, 'x':connectivityStart.x, 'y':connectivityStart.y,
                        'width':1000, 'height':2*pointRadius});
                }
            };

            findPowerBounds = function()
            {
                var sleepEvent = null,
                    wakeEvent  = null,
                    isConnected = false,
                    boundType = 'Sleep',
                    i;
                
                // Find the initial connected state
                for(i = snapshots.length - 1; i &gt;= 0; i-- )
                {
                    if( snapshots[i].type === 'Disconnect' ) {
                        isConnected = true;
                        break;
                    } else if (snapshots[i].type === 'Connect'){
                        isConnected = false;
                        break;
                    }
                }
                
                // Generate power bounds
                for(i = snapshots.length - 1; i &gt;= 0; i--)
                {
                    if(snapshots[i].type === 'CS-Sleep' || snapshots[i].type === 'Sleep')
                    {
                        sleepEvent = snapshots[i];
                    }
                    else if( snapshots[i].type === 'CS-Wake' || snapshots[i].type === 'Wake')
                    {
                        wakeEvent = snapshots[i];

                        // If we have a sleep and a wake, draw a bounds between them
                        if(sleepEvent !== null &amp;&amp; wakeEvent !== null) {
                            
                            // If we are connected to a network and the power event is a connected standby
                            // sleep, draw a light green box for the time asleep signifying that the 
                            // connection is still active
                            if( isConnected &amp;&amp; sleepEvent.type === 'CS-Sleep')
                            {
                                boundType = 'CS-Sleep';
                            }
                            else
                            {
                                boundType = 'Sleep';
                            }
                            
                            powerBounds.push({'type':boundType, 'sleepEvent':sleepEvent, 'wakeEvent':wakeEvent, 'x':sleepEvent.x, 'y':wakeEvent.y,
                                'width':wakeEvent.x - sleepEvent.x, 'height':200});
                        }

                        sleepEvent = null;
                        wakeEvent = null;
                    }
                    else if( snapshots[i].type === 'Connect')
                    {
                        isConnected = true;
                    }
                    else if( snapshots[i].type === 'Disconnect')
                    {
                        isConnected = false;
                    }
                }
            };

            drawSessionBounds = function(canvas)
            {
                var graph,
                    session,
                    i;

                graph = canvas.getContext('2d');

                if(wlanBounds)
                {
                    for(i = wlanBounds.length - 1; i &gt;= 0; i--)
                    {
                        session = wlanBounds[i];
                        drawBound(graph, 'Connect', session.x, session.width);
                    }
                }

                if(powerBounds)
                {
                    for(i = powerBounds.length - 1; i &gt;= 0; i--)
                    {
                        session = powerBounds[i];
                        drawBound(graph, session.type, session.x, session.width);
                    }
                }

                // Draw Internet/Limited connectivity bounds
                graph.fillStyle = "rgba(235,235,0,0.4)";
                graph.strokeStyle = "rgba(30,30,30,0.8)";
                graph.lineWidth = 1;


                if(connectivityBounds)
                {
                    for(i = 0; i &lt; connectivityBounds.length; i++)
                    {
                        session = connectivityBounds[i];
                        if(session.startEvent.type === 'Local')
                        {
                            graph.fillStyle = "rgba(235,235,0,0.4)";
                        }
                        else if(session.startEvent.type === 'None')
                        {
                            graph.fillStyle = "rgba(235,0,0,0.4)";
                        }
                        else
                        {
                            // Don't draw bounds when the capability is internet
                            continue;
                            //graph.fillStyle = "rgba(156,202,245,0.6)";
                        }

                        graph.fillRect( session.x, session.y - pointRadius, session.width, session.height);
                    }
                }
            };

            drawBound = function(graph, type, x, width)
            {
                var style,
                    y      = 50,
                    height = 200;

                if(type === 'Connect' || type === 'Disconnect')
                {
                    style = boundRenderInfo['Connected'];
                }
                else if(type === 'Sleep' || type === 'Wake')
                {
                    style = boundRenderInfo['Power'];
                }
                else if(type === 'CS-Sleep' || type === 'CS-Wake' )
                {
                    style = boundRenderInfo['ConnectedStandby'];
                }
                else
                {
                    style = boundRenderInfo['Connected'];
                }

                graph.fillStyle = style['fill'];
                graph.strokeStyle = style['stroke'];
                graph.lineWidth = style['lineWidth'];

                graph.fillRect(x, y, width, height);
                graph.strokeRect(x, y, width, height);
            }

            drawAxis = function(canvas)
            {
                var graph,
                    width,
                    height,
                    xPadding,
                    yPadding,
                    step,
                    twoDaysInHours = 48,
                    i;

                width = canvas.width;
                height = canvas.height;
                xPadding = 10;
                yPadding = 15;

                graph = canvas.getContext('2d');


                // Separate WLAN/NCSI/NDIS events
                // into their own 'lanes'
                graph.fillStyle = "#141414";
                graph.fillRect(0, 0, width, 100);   //WLAN lane
                graph.fillRect(0, 200, width, 100); //NDIS lane
                
                //Draw a line for each of the 48 hours in 2 days
                graph.strokeStyle = "#333";
                graph.lineWidth = 1;
                graph.font = "12px sans-serif";
                graph.fillStyle = "#555";
                graph.textAlign = "center";

                step = width/twoDaysInHours;

                for( i = 0; i &lt; twoDaysInHours; i++)
                {
                    graph.beginPath();
                    graph.moveTo((step * i), 0);
                    graph.lineTo((step * i), height - yPadding);
                    graph.stroke();
                }

                // Label X axis
                graph.fillText('Oldest', 30, height - 5);
                graph.fillText('Newest', width - 30, height - 5);
            };

            drawEventRegionLabels = function(canvas)
            {
                var graph = canvas.getContext('2d');

                // Label event regions
                graph.font = "12px sans-serif";
                graph.textAlign = "center";
                graph.strokeStyle = "#333";
                graph.lineWidth = 1;

                graph.fillStyle = "#050505";
                //WLAN
                graph.fillRect(0, 0, 40, 20);
                graph.strokeRect(0,0,40,20);
                //NCSI
                graph.fillRect(0, 101, 40, 20);
                graph.strokeRect(0,101,40,20);
                //NDIS
                graph.fillRect(0, 201, 40, 20);
                graph.strokeRect(0,201,40,20);

                graph.fillStyle = "#EEE";
                graph.fillText('WLAN', 20, 15);
                graph.fillText('NCSI', 20, 115);
                graph.fillText('NDIS', 20, 215);
            };

            drawLegend = function()
            {
                var canvas,
                    legend,
                    width,
                    height,
                    x;

                canvas = document.getElementById('graph-legend');
                width = canvas.width;
                height = canvas.height;
                symbolX = 20;
                textX = 40;

                legend = canvas.getContext('2d');

                // Connect
                legend.fillStyle = eventRenderInfo['Connect'].color;
                drawPoint(legend, symbolX, 10, eventRenderInfo['Connect'].label);
                drawLegendLabel(legend, textX, 13, "- Started a connection");

                // Disconnect
                legend.fillStyle = eventRenderInfo['Disconnect'].color;
                drawPoint(legend, symbolX, 30, eventRenderInfo['Disconnect'].label);
                drawLegendLabel(legend, textX, 33, "- Disconnected from a network");

                // Sleep
                legend.fillStyle = eventRenderInfo['Sleep'].color;
                drawPoint(legend, symbolX, 50, eventRenderInfo['Sleep'].label);
                drawLegendLabel(legend, textX, 53, "- Wireless adapter entered a low power state");

                // Wake
                legend.fillStyle = eventRenderInfo['Wake'].color;
                drawPoint(legend, symbolX, 70, eventRenderInfo['Wake'].label);
                drawLegendLabel(legend, textX, 73, "- Wireless adapter entered a working power state");

                // Capability Internet
                legend.fillStyle = eventRenderInfo['Internet'].color;
                drawPoint(legend, symbolX, 90, eventRenderInfo['Internet'].label);
                drawLegendLabel(legend, textX, 93, "- Network is connected to the internet");

                // Capability Local
                legend.fillStyle = eventRenderInfo['Local'].color;
                drawPoint(legend, symbolX, 110, eventRenderInfo['Local'].label);
                drawLegendLabel(legend, textX, 113, "- Network has limited connectivity");

                // Capability None
                legend.fillStyle = eventRenderInfo['None'].color;
                drawPoint(legend, symbolX, 130, eventRenderInfo['None'].label);
                drawLegendLabel(legend, textX, 133, "- Network has no connectivity");

                // Error
                legend.fillStyle = eventRenderInfo['Error'].color;
                drawPoint(legend, symbolX, 150, eventRenderInfo['Error'].label);
                drawLegendLabel(legend, textX, 153, "- Error");
            };

            drawLegendLabel = function(legend, x, y, text)
            {
                legend.font = "14px sans-serif";
                legend.fillStyle = '#DDD';
                legend.textAlign = "left";
                legend.fillText(text, x, y);
            };

            drawSessionGraph = function()
            {
                var canvas,
                    events;

                canvas = document.getElementById('session-graph');

                calculateEventCoordinates(canvas);

                drawAxis(canvas);

                findwlanBounds();
                findConnectivityBounds();
                findPowerBounds();
                drawSessionBounds(canvas);

                drawEvents(canvas);

                drawEventRegionLabels(canvas);

                drawLegend();

                canvas.addEventListener('click', eventClickHandler, false);
                canvas.addEventListener('mousemove', eventMouseMoveHandler, false);
            };

            eventClickHandler = function(e)
            {
                var canvas = document.getElementById('session-graph'),
                    x,
                    y,
                    snapshot,
                    originalClass;

                e = e || window.event;

                if( e.stopPropogation )
                {
                    e.stopPropogation();
                } else {
                    e.cancelBubble = true;
                }

                x = e.offsetX;
                y = e.offsetY;

                snapshot = getSnapshotAtXY(x,y);
                
                // Emphasize the selected event by placing a border
                // around it that dissapears after one second
                if( snapshot !== null)
                {
                    window.location.hash = snapshot.correspondingEvent;
                    evtElement = document.getElementById(snapshot.correspondingEvent).parentNode.parentNode;
                    originalClass = evtElement.className;
                    evtElement.className = evtElement.className + ' glow';

                    setTimeout(function(){
                        evtElement.className = originalClass;
                    }, 1000);
                }
            };

            eventMouseMoveHandler = function(e)
            {
                var summary,
                    x,
                    y,
                    snapshot,
                    session,
                    startEvent = null,
                    endEvent   = null,
                    i;

                e = e || window.event;

                if( e.stopPropogation )
                {
                    e.stopPropogation();
                } else {
                    e.cancelBubble = true;
                }

                x = e.offsetX;
                y = e.offsetY;
                summary = document.getElementById('event-info');

                snapshot = getSnapshotAtXY(x,y);

                summary.innerHTML = "Hover over a session or event to view a summary <br/> Click on an event to jump to it in the session list";
                
                // Handle mouseover on snapshot events
                if(snapshot !== null)
                {
                    if(snapshot.type === 'Connect')
                    {
                        summary.innerHTML = 'Started a connection to a wireless network <br/>' +
                        '<br/>' + snapshot.date + '<br/>' +
                        'Connection mode: ' + snapshot.connectionMode + '<br/>' +
                        'Profile: ' + snapshot.profileName + '<br/>' +
                        'SSID: ' + snapshot.ssid;
                    }
                    else if(snapshot.type === 'Disconnect')
                    {
                        summary.innerHTML = snapshot.disconnectReason + '<br/>' +
                        '<br/>' + snapshot.date + '<br/>' +
                        'Connection mode: ' + snapshot.connectionMode + '<br/>' +
                        'Profile: ' + snapshot.profileName + '<br/>' +
                        'SSID: ' + snapshot.ssid;
                    }
                    else if( snapshot.type === 'Wake' || snapshot.type === 'CS-Wake' ||
                            snapshot.type === 'Sleep' || snapshot.type === 'CS-Sleep' )
                    {
                        summary.innerHTML = snapshot.message + '<br/>' +
                        '<br/>' + snapshot.date + '<br/>';

                    }
                    else if(snapshot.type === 'Internet' || snapshot.type == 'Local' || snapshot.type == 'None')
                    {
                        summary.innerHTML = snapshot.message + '<br/>' +
                        '<br/>' + snapshot.date + '<br/>';

                    }
                    else if( snapshot.type === 'Error' )
                    {
                        var messageCutoffIndex = 0;
                        messageCutoffIndex = snapshot.message.indexOf('br') - 1;
                        summary.innerHTML = snapshot.message.substring(0,messageCutoffIndex) + '<br/>' +
                        '<br/>' + snapshot.date + '<br/>';
                    }

                    return;
                }

                session = getSessionAtXY(x,y);
                
                // Handle mouseover on session bounds
                if( session !== null)
                {
                    startEvent = session.connectEvent;
                    endEvent = session.disconnectEvent;
                    if(startEvent !== null &amp;&amp; endEvent !== null)
                    {
                        summary.innerHTML = 'Session duration: ' + calculateSessionDuration(startEvent.time, endEvent.time) + '<br/>' +
                        'Start time: ' + startEvent.date.toLocaleString() + '<br/>' +
                        'End time: ' + endEvent.date.toLocaleString() + '<br/>' +
                        'Disconnect reason: ' + endEvent.disconnectReason + '<br/>';
                    }
                    else if(startEvent !== null)
                    {
                        summary.innerHTML = 'Session duration: Ongoing' + '<br/>' +
                        'Start time: ' + startEvent.date.toLocaleString() + '<br/>';
                    }
                    else if(endEvent !== null)
                    {
                        summary.innerHTML = 'End time: ' + endEvent.date.toLocaleString() + '<br/>' +
                        'Disconnect reason: ' + endEvent.disconnectReason + '<br/>';
                    }
                }
            };

            calculateSessionDuration = function(start, end )
            {
                var duration = (end - start) / 1000,
                    hours    = parseInt( duration / (60 * 60), 10),
                    minutes  = parseInt((duration / 60) % 60, 10),
                    seconds  = Math.round(duration % 60);

                return (hours + ' hours ' + minutes + ' minutes ' + seconds + ' seconds');
            };

            getSnapshotAtXY = function(x, y)
            {
                var snapshot,
                    i;

                // Check to see if the mouse pointer correspondes to an event
                for(i = 0; i &lt; snapshots.length; i++)
                {
                    snapshot = snapshots[i];
                    if( x &gt;= snapshot.x - pointRadius &amp;&amp; x &lt;= snapshot.x + pointRadius )
                    {
                        if(y &gt;= snapshot.y - pointRadius &amp;&amp; y &lt;= snapshot.y + pointRadius)
                        {
                            return snapshot;
                        }
                    }
                }

                return null;
            };

            getSessionAtXY = function(x, y)
            {
                var session,
                    i;

                // Check to see if the mouse pointer corresponds to a session
                for(i = 0; i &lt; wlanBounds.length; i++)
                {
                    session = wlanBounds[i];
                    if( x &gt;= session.x &amp;&amp; x &lt;= session.x + session.width )
                    {
                        if(y &gt;= session.y &amp;&amp; y &lt;= session.y + session.height)
                        {
                            return session;
                        }
                    }
                }

                return null;
            };

            convertSnapshotTimes = function()
            {
                var i;
                for(i = 0; i &lt; snapshots.length; i++)
                {
                    snapshots[i].time = convertFileTimeToUnixTime(snapshots[i].time);
                    snapshots[i].date = new Date(snapshots[i].time);
                }
            };

            convertFileTimeToUnixTime = function(time)
            {
                var nanoSecondsPerMS   = 10000,
                    yearDifferenceInMS = 11644473600000; //MS between 1601 and 1970

                return (time / nanoSecondsPerMS) - yearDifferenceInMS;
            };
			
            fixCommandOutputFormatting = function()
            {
                var commandTextboxes = document.getElementsByTagName("textarea"),
                    textbox,
                    i;
				
                for(i in commandTextboxes)
                {
                    textbox = commandTextboxes[i];
                    if(textbox.className === "command-output")
                    {
	                    var output = textbox.innerHTML;
	                    output = output.replace(/\n\n\n\n/g, '\n');
	                    textbox.innerHTML = output.trim();
                    }
                }
				
            };
			
            checkForEmptyReport = function()
            {
                var sessionList = document.getElementById('session-list'),
                    eventsSummary;
				
                if(sessionList.innerHTML == '')
                {
                    sessionList.innerHTML = "<h4>No WLAN events were found on this system.</h4>";
                    sessionList.style.margin = "0 0 100px 0";
					
                    eventsSummary =  document.getElementById('events-summary');
                    eventsSummary.parentNode.removeChild(eventsSummary);
                }
            };
			
            bindTopBtn = function()
            {
                var btn           = document.getElementById('top-btn'),
                    reportWrapper = document.getElementById('report-wrapper');

                btn.style.left = (reportWrapper.offsetLeft - btn.clientWidth - 20) + 'px';
                btn.style.top = '30px';

                btn.addEventListener('click', function() {
                    window.scrollTo(0,0);
                    window.history.replaceState({}, '', window.location.href.split('#')[0]);
                }, false);
            };

            wlanReport.initialize = function()
            {
                bindTopBtn();
                bindToggleMessageBtns();
                convertSnapshotTimes();
                drawSessionGraph();
                fixCommandOutputFormatting();
                checkForEmptyReport();
            };

            return wlanReport;
        }());

        window.addEventListener('load', wlanReport.initialize, false);
    </xsl:template>

    <!--Replace gratuitous line breaks in event messages with single <br>'s-->
    <xsl:template name="replace">
        <xsl:param name="message"/>

        <!-- \r\n\r\n sequence -->
        <xsl:variable name="linebreak" select="'&#13;&#10;&#13;&#10;'" />

        <xsl:choose>
            <xsl:when test="contains($message, $linebreak)">
                <xsl:value-of select="substring-before($message, $linebreak)"/>
                    <br/>
				<xsl:call-template name="replace">
                    <xsl:with-param name="message" select="substring-after($message, $linebreak)"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$message"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
	
	<!--Special replace function to properly format the WCM preferred interface list-->
    <xsl:template name="replaceSingleNewlines">
        <xsl:param name="message"/>

        <!-- \r\n sequence -->
        <xsl:variable name="linebreak" select="'&#13;&#10;'" />

        <xsl:choose>
            <xsl:when test="contains($message, $linebreak)">
                <xsl:value-of select="substring-before($message, $linebreak)"/>
                    <br/>
				<xsl:call-template name="replaceSingleNewlines">
                    <xsl:with-param name="message" select="substring-after($message, $linebreak)"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$message"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
	
    <xsl:template match="/WlanReport">
        <html>
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="X-UA-Compatible" content="IE=edge" />
            <title>wlan report</title>
            
            <!-- Include the css into the output file-->
            <xsl:call-template name="css" />
        </head>
        <body>
            <div id="top-btn">
                <p>Top</p>
            </div>
            <div id="report-wrapper">
                <h1>Wlan Report</h1>
                <div id="session-graph-wrapper">
                    <canvas id="session-graph" width="1000" height="315"></canvas>
                    <div id="graph-event-info">
                        <h4>Summary</h4>
                        <p id="event-info">
                            Hover over a session or event to view a summary <br />
                            Click on an event to jump to it in the session list
                        </p>
                    </div>
                    <canvas id="graph-legend" width="400" height="170"></canvas>
                </div>
                <div id="report-info">
                    <h2>Report Info</h2>
                    <p>Report created:<b><xsl:value-of select="ReportInformation/ReportDate" /></b></p>
                    <p>Report duration:<b><xsl:value-of select="ReportInformation/ReportDuration" /> days</b></p>
                </div>
                <div id="sysinfo">
                    <xsl:choose>
                        <xsl:when test="not(SystemInformation/ComputerName = '')">
                            <h2>General System Info</h2>
                            <p>ComputerName: <b><xsl:value-of select="SystemInformation/ComputerName" /></b></p>
                            <p>System Manufacturer:<b><xsl:value-of select="SystemInformation/SystemManufacturer" /></b></p>
                            <p>System Product Name:<b><xsl:value-of select="SystemInformation/SystemProductName" /></b></p>
                            <p>BIOS Date:<b><xsl:value-of select="SystemInformation/BIOSDate" /></b></p>
                            <p>BIOS Version:<b><xsl:value-of select="SystemInformation/BIOSVersion" /></b></p>
                            <p>OS Build:<b><xsl:value-of select="SystemInformation/OSBuild" /></b></p>
                            <p>Machine Id: <b><xsl:value-of select="SystemInformation/MachineId" /></b></p>
                            <p>MDM joined: 
                                <xsl:choose>
                                  <xsl:when test="SystemInformation/MDMRegistered = '1'">
                                      <b>True</b>
                                  </xsl:when>
                                  <xsl:when test="SystemInformation/MDMRegistered = '0'">
                                      <b>False</b>
                                  </xsl:when>
                                  <xsl:otherwise>
                                      <b>Unknown</b>
                                  </xsl:otherwise>
                                </xsl:choose>
                            </p>
							
                            <h2>User Info</h2>
                            <p>Username: <b><xsl:value-of select="UserInformation/Username" /></b></p>
                            <p>User Domain:<b><xsl:value-of select="UserInformation/UserDomain" /></b></p>
                            <p>User DNS Domain:<b><xsl:value-of select="UserInformation/UserDnsDomain" /></b></p>
                        </xsl:when>
                    </xsl:choose>
                    <h2>Network Adapters</h2>
                    <xsl:for-each select="SystemInformation/NetworkAdapters/Adapter">
                        <p>Device: <b><xsl:value-of select="Name" /></b></p>						
                        <p>PNP ID: <b><xsl:value-of select="PnpId" /></b></p>
                        <p>Guid: <b><xsl:value-of select="Guid" /></b></p>
                        <p>Current driver version: <b><xsl:value-of select="DriverVersion" /></b></p>
                        <p>Driver date: <b><xsl:value-of select="DriverDate" /></b></p>
                        <p>DevNode flags: <b><xsl:value-of select="DevNodeFlags" /></b></p>
                        <xsl:choose>
                            <xsl:when test="not(ProblemNumber = '')">
                                <p>Problem number: <b><xsl:value-of select="ProblemNumber" /></b></p>
                            </xsl:when>
                        </xsl:choose>
                        <br />
                    </xsl:for-each>
                </div>
				
                <div id="commands-output">
                    <h2>Script Output</h2>
                    <xsl:for-each select="ScriptOutput/CustomCommand">
                        <h3> Output for <em>'<xsl:value-of select="Command" />'</em></h3>
                        <textarea class="command-output" cols="91" rows="25" readonly="true" spellcheck="false">
                        <xsl:value-of select="Output" />
                        </textarea>
                    </xsl:for-each>
                </div>
              
                <div id="commands-output">
                    <h2>Profile Output</h2>
                    <textarea class="command-output" cols="91" rows="25" readonly="true" spellcheck="false">
                        <xsl:for-each select="Profiles/Interface">
                            <xsl:for-each select="Profile">
                                <xsl:text>&#13;</xsl:text><xsl:comment>Interface: <xsl:value-of select="../@name"/>, Profile: <xsl:value-of select="./@name"/></xsl:comment><xsl:text>&#13;</xsl:text>
                                <xsl:value-of select="." />
                            </xsl:for-each>
                        </xsl:for-each>
                    </textarea>
                </div>
				
                <div id="events-summary">
                    <h2>Summary</h2>
                    <h3>Session Success/Failures</h3>
                    <table id="disconnect-status">
                        <xsl:variable name="max-status-width" select="300" />
                        <tr>
                            <th>Status</th>
                            <th>Count</th>
                        </tr>
                        <tr>
                            <td class="status">
                                <span class="graph-background success">
                                    <xsl:attribute name="style">
                                        <xsl:value-of select="concat('width: ', format-number( (WlanEventsSummary/StatusSummary/Successful div WlanEventsSummary/@total) * $max-status-width, '0.##'), 'px')" />
                                    </xsl:attribute>
                                    &#160;
                                </span>
                                Successes
                            </td>
                            <td class="count">
                                <xsl:value-of select="WlanEventsSummary/StatusSummary/Successful" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="graph-background failure">
                                    <xsl:attribute name="style">
                                        <xsl:value-of select="concat('width: ', format-number( (WlanEventsSummary/StatusSummary/Failed div WlanEventsSummary/@total) * $max-status-width, '0.##'), 'px')" />
                                    </xsl:attribute>
                                    &#160;
                                </span>
                                Failures
                            </td>
                            <td class="count">
                                <xsl:value-of select="WlanEventsSummary/StatusSummary/Failed" />
                            </td>
                        </tr>
                        <tr>
                            <td class="status">
                                <span class="graph-background warning">
                                    <xsl:attribute name="style">
                                        <xsl:value-of select="concat('width: ', format-number( (WlanEventsSummary/StatusSummary/Warning div WlanEventsSummary/@total) * $max-status-width, '0.##'), 'px')" />
                                    </xsl:attribute>
                                    &#160;
                                </span>
                                Warnings
                            </td>
                            <td class="count">
                                <xsl:value-of select="WlanEventsSummary/StatusSummary/Warning" />
                            </td>
                        </tr>
                    </table>

                    <h3>Disconnect Reasons</h3>
                    <table id="disconnect-reasons">
                        <tr>
                            <th>Reason</th>
                            <th>Count</th>
                        </tr>
                        <xsl:variable name="max-reason-width" select="800" />
                        <xsl:for-each select="WlanEventsSummary/DisconnectReasons/Reason">
                            <xsl:sort select="@count" data-type="number" order="descending" />
                            <tr>
                                <td class="reason">
                                    <span class="graph-background">
                                        <xsl:attribute name="style">
                                            <xsl:value-of select="concat('width: ', format-number((@count div ../../@total) * $max-reason-width, '0.##'), 'px')" />
                                        </xsl:attribute>
                                        <xsl:attribute name="class">
                                            graph-background <xsl:value-of select="@type" />
                                        </xsl:attribute>
                                        &#160;
                                    </span>
                                    <xsl:value-of select="@message" />
                                </td>
                                <td class="count">
                                    <xsl:value-of select="@count" />
                                </td>
                            </tr>
                        </xsl:for-each>
                    </table>
                    <h3>Session Durations</h3>
                    <table id="session-durations">
                        <tr id="duration-graph">
                            <!--Find the most frequent duration. This will be the tallest bar others are scaled against-->
                            <xsl:variable name="duration-mode"
                                          select="WlanEventsSummary/SessionDurations/Duration[not(../Duration > .)]" />
                            <xsl:variable name="max-height" select="520" />
                            <xsl:for-each select="WlanEventsSummary/SessionDurations/Duration">

                                <xsl:variable name="bar-height-ratio" select=". div $duration-mode" />

                                <!--Make sure the bar height has a minimum value of 0 -->
                                <xsl:variable name="bar-height">
                                    <xsl:choose>
                                        <xsl:when test="string(number($bar-height-ratio))='NaN'">0</xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="format-number( $max-height * $bar-height-ratio, '0')" />
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:variable>

                                <td>
                                    <xsl:attribute name="style">
                                        <xsl:value-of select="concat('top: ', 550 - $bar-height, 'px;')" />
                                    </xsl:attribute>
                                    <div class="duration-bar">
                                        <xsl:attribute name="style">
                                            <xsl:value-of select="concat('height: ', $bar-height, 'px;')" />
                                        </xsl:attribute>
                                        <span class="bar-label">
                                            <xsl:attribute name="style">
                                                <xsl:value-of select="concat('bottom: ', $bar-height, 'px;')" />
                                            </xsl:attribute>
                                            <xsl:value-of select="." />
                                        </span>
                                        <span class="bar-background">
                                            &#160;
                                        </span>
                                    </div>
                                </td>
                            </xsl:for-each>
                        </tr>
                        <tr id="duration-labels">
                            <xsl:for-each select="WlanEventsSummary/SessionDurations/Duration">
                                <td>
                                    <xsl:value-of select="@time" /><br />minutes
                                </td>
                            </xsl:for-each>
                        </tr>
                    </table>
                </div>
				
                <h2>Wireless Sessions</h2>
                <div id="session-list">
                    <xsl:for-each select="WlanEvents/WlanSession">
                        <div class="session">
                            <xsl:choose>
                                <xsl:when test="@success != 3">
                                    <!-- 3 is the Id of standalone events not tied to a session. Do not show a summary for these events-->
                                    <p>Interface:<b><xsl:value-of select="@interface" /></b></p>
                                    <p>Interface GUID: <b><xsl:value-of select="@guid" /></b></p>
                                    <p>Connection Mode:<b><xsl:value-of select="@mode" /></b></p>
                                    <p>Profile:<b><xsl:value-of select="@profile" /></b></p>
                                    <p>SSID:<b><xsl:value-of select="@ssid" /></b></p>
                                    <p>BSS Type:<b><xsl:value-of select="@bss" /></b></p>
                                    <p>Session Duration:
                                        <b>
                                            <!-- Initial duration is in seconds. Manipulate it into a readable string -->
                                            <xsl:value-of select="format-number(floor(@duration div (60 * 60)), '0')" /> hours
                                            <xsl:value-of select="format-number(floor((@duration div 60) mod 60), '0')" /> minutes
                                            <xsl:value-of select="format-number(floor(@duration mod 60), '0')" /> seconds
                                        </b>
                                    </p>
                                    <p>Disconnect Reason:<b><xsl:value-of select="@disconnect" /></b></p>
                                </xsl:when>
                            </xsl:choose>
                            <table>
                                <xsl:choose>
                                    <xsl:when test="@success = 0">
                                        <!--Successful session-->
                                        <tr class="successful">
                                            <th class="event-header">EventId</th>
                                            <th class="time-header">Time</th>
                                            <th class="message-header">Message</th>
                                        </tr>
                                    </xsl:when>
                                    <xsl:when test="@success = 1">
                                        <!--Warning session-->
                                        <tr class="warning">
                                            <th class="event-header">EventId</th>
                                            <th class="time-header">Time</th>
                                            <th class="message-header">Message</th>
                                        </tr>
                                    </xsl:when>
                                    <xsl:when test="@success = 3">
                                        <!--Info session-->
                                        <tr class="info">
                                            <th class="event-header">EventId</th>
                                            <th class="time-header">Time</th>
                                            <th class="message-header">Message</th>
                                        </tr>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <tr class="failed">
                                            <th class="event-header">EventId</th>
                                            <th class="time-header">Time</th>
                                            <th class="message-header">Message</th>
                                        </tr>
                                    </xsl:otherwise>
                                </xsl:choose>
                                <xsl:for-each select="WlanEvent">
                                    <tr>
                                        <xsl:attribute name="class">
                                            <xsl:choose>
                                                <xsl:when test="@error > 0">
                                                    error
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:value-of select="@type" />
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:attribute>
                                        <td>
                                            <xsl:value-of select="EventID" />
                                            <a>
                                                <xsl:attribute name="id">
                                                    <xsl:value-of select="UID" />
                                                </xsl:attribute>
                                            </a>
                                        </td>
                                        <td>
                                            <xsl:value-of select="EventTime" />
                                        </td>
                                        <td>
                                            <div class="message">
                                                <span class="expand-btn">[+]</span>
                                                <span class="message-body">
                                                    <xsl:choose>
                                                        <xsl:when test="EventID = 1020">
                                                            <xsl:call-template name="replaceSingleNewlines">
                                                                <xsl:with-param name="message" select="EventMessage" />
                                                            </xsl:call-template>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <xsl:call-template name="replace">
                                                                <xsl:with-param name="message" select="EventMessage" />
                                                            </xsl:call-template>
                                                        </xsl:otherwise>
                                                    </xsl:choose>
                                                </span>
                                            </div>
                                        </td>
                                    </tr>
                                </xsl:for-each>
                            </table>
                        </div>
                    </xsl:for-each>
                </div>
            </div>
        
            <!--Write out all of the snapshot information-->
            <script type="text/javascript">
                var snapshots = [
                    <xsl:for-each select="SessionSnapshot/Session">
                        {
                            "type":"<xsl:value-of select="EventType"/>",
                            "error":"<xsl:value-of select="EventError"/>",
                            "time":"<xsl:value-of select="EventTime"/>",
                            "message":"<xsl:call-template name="replace">
                                            <xsl:with-param name="message" select="EventMessage"/>
                                        </xsl:call-template>",
                            "connectionMode":"<xsl:value-of select="EventConnectionMode"/>",
                            "profileName":"<xsl:value-of select="EventProfileName"/>",
                            "ssid":"<xsl:value-of select="EventSSID"/>",
                            "disconnectReason":"<xsl:value-of select="EventDisconnectReason"/>",
                            "correspondingEvent":"<xsl:value-of select="CorrespondingEvent"/>" 
                        },
                    </xsl:for-each>
                ];
            
                <!-- Include the javascript into the output file-->
                <xsl:call-template name="js"/>
            </script>
        </body>
    </html>
  </xsl:template>

</xsl:stylesheet>
PPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPAD