<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd" />
	<xsl:template match="/">
		<html>
			<head>
				<title>FolderSizes XML Format Report</title>
				<style type="text/css">
          body     { font-family: Arial; font-size: 12px; }
          table    { padding: 0; border-width: 0; border-spacing: 0 }
          h1       { color: #000080 }
          th       { color: #FFFFFF; background-color: #808080; }
          td			 { font-size: 12px; padding-left: 5px; padding-right: 5px }
        </style>
			</head>
			<body>
				<h1>FolderSizes (v<xsl:value-of select="FolderSizes/Version"/>) XML Format Report</h1>
				<h2><xsl:value-of select="FolderSizes/DateTime"/></h2>

				<strong>Total scan size: <xsl:value-of select="FolderSizes/Summary/TotalSize"/></strong> <br/>
				<strong>Total allocated scan size: <xsl:value-of select="FolderSizes/Summary/TotalAllocated"/></strong> <br/>
				<strong>Average file size: <xsl:value-of select="FolderSizes/Summary/TotalAvgFileSize"/></strong> <br/>
				<strong>Total folders scanned: <xsl:value-of select="FolderSizes/Summary/TotalFolders"/></strong> <br/>
				<strong>Total files scanned: <xsl:value-of select="FolderSizes/Summary/TotalFiles"/></strong> <br/>

				<!-- disk space info table -->
				<p>
					<table width="100%" style="background-color: #E1F0FF; border: 1px solid #C0C0C0;">
						<tbody>
							<tr>
								<th>Drive</th>
								<th>Type</th>
								<th>Total</th>
								<th>Free</th>
								<th>Used</th>
							</tr>
							<xsl:for-each select="FolderSizes/DiskSpaceInfo/Drive">
								<xsl:call-template name="DiskInfo">
									<xsl:with-param name="Drive" select="."/>
								</xsl:call-template>
							</xsl:for-each>
						</tbody>
					</table>
				</p>

				<!-- folder info table -->
				<p>
					<table width="100%" border="0" style="border: 1px solid #C0C0C0;">
						<tbody>
							<tr>
								<th>Name</th>
								<th>Size</th>
								<th>Allocated</th>
								<th>Avg. Size</th>
								<th>Files</th>
								<th>Folders</th>
								<th>Depth</th>
								<th>Last Modified</th>
								<th>% of Parent</th>
								<th>Owner</th>
								<th>Attribs</th>
							</tr>
							<xsl:for-each select="FolderSizes/Folder">
								<xsl:call-template name="RecurseTree">
									<xsl:with-param name="Path" select="."/>
								</xsl:call-template>
							</xsl:for-each>
						</tbody>
					</table>
				</p>
			</body>
		</html>
	</xsl:template>

	<xsl:template name="DiskInfo">
		<xsl:param name="Drive"/>
		<xsl:call-template name="DisplayDiskInfoRow">
			<xsl:with-param name="Drive" select="$Drive"/>
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="DisplayDiskInfoRow">
		<xsl:param name="Drive"/>
		<tr>
			<td><xsl:value-of select="$Drive"/></td>
			<td><xsl:value-of select="$Drive/@Type"/></td>
			<td><xsl:value-of select="$Drive/@Total"/></td>
			<td><xsl:value-of select="$Drive/@Free"/></td>
			<td><xsl:value-of select="$Drive/@Used"/></td>
		</tr>
	</xsl:template>

	<xsl:template name="RecurseTree">
		<xsl:param name="Path"/>
		<xsl:call-template name="DisplayPathRow">
			<xsl:with-param name="Path" select="$Path"/>
		</xsl:call-template>
		<xsl:for-each select="$Path/Folder">
			<xsl:call-template name="RecurseTree">
				<xsl:with-param name="Path" select="."/>
			</xsl:call-template>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="RecurseParent">
		<xsl:param name="Path"/>
		<xsl:for-each select="$Path/parent::Folder">
			<xsl:call-template name="RecurseParent">
				<xsl:with-param name="Path" select="."/>
			</xsl:call-template>
		</xsl:for-each>
    <xsl:value-of select="concat(Name, '\')"/>
  </xsl:template>

<xsl:template name="DisplayPathRow">
	<xsl:param name="Path"/>
	<tr>
		<!--<td style="padding-left:{count(ancestor::Folder)*10}px"><xsl:value-of select="$Path/Name"/></td>-->
		<td width="20%">
			<xsl:call-template name="RecurseParent">
				<xsl:with-param name="Path" select="."/>
			</xsl:call-template>
		</td>
		<td width="10%"><xsl:value-of select="$Path/Size"/></td>
		<td width="10%"><xsl:value-of select="$Path/Allocated"/></td>
		<td width="10%"><xsl:value-of select="$Path/AvgFileSz"/></td>
		<td width="5%"><xsl:value-of select="$Path/Files"/></td>
		<td width="5%"><xsl:value-of select="$Path/Folders"/></td>
		<td width="5%"><xsl:value-of select="$Path/Depth"/></td>
		<td width="10%"><xsl:value-of select="$Path/LastMod"/></td>
		<td width="5%"><xsl:value-of select="$Path/Percentage"/></td>
		<td width="10%"><xsl:value-of select="$Path/Owner"/></td>
		<td width="10%"><xsl:value-of select="$Path/Attribs"/></td>
	</tr>
</xsl:template>

</xsl:stylesheet>
