<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:key name="names" match="Row" use="substring-after(Assigned_x0020_To,'#')"/>

	<xsl:template match="/">
		<html>
			<head>
				<title>Resource Allocator</title>
			</head>
			<body>
				<table border="0">
					<tr>
						<th>
							<font color="#CA226B">Name</font>
							<hr/>
						</th>
						<th>
							<font color="#CA226B">% Allocated</font>
							<hr/>
						</th>
						<th>
							<font color="#CA226B">Free Date</font>
							<hr/>
						</th>
						<th>
							<font color="#CA226B">Avg. Priority</font>
							<hr/>
						</th>
					</tr>
					<xsl:for-each select="/Rows/Row[generate-id() = generate-id(key('names', substring-after(Assigned_x0020_To,'#'))[1])]">
						<xsl:variable name="name" select="substring-after(Assigned_x0020_To,'#')"/>
						<tr>
							<xsl:choose>
								<xsl:when test="Percent_x0020_Bandwidth*100 &lt; 90">
									<td bgcolor="#00FF00">
										<xsl:value-of select="$name"/>
									</td>
								</xsl:when>
								<xsl:when test="Percent_x0020_Bandwidth*100 &gt;= 90">
									<td bgcolor="#FF0000">
										<xsl:value-of select="$name"/>
									</td>
								</xsl:when>
								<xsl:otherwise>
									<td>
										<xsl:value-of select="$name"/>
									</td>
								</xsl:otherwise>
							</xsl:choose>
							<td>
								<center>
									<xsl:value-of select="sum(//Row[substring-after(Assigned_x0020_To,'#') = $name]/Percent_x0020_Bandwidth) * 100 "/>
								</center>
							</td>
							<td>
								<center>
									<xsl:value-of select="substring-before(Due_x0020_Date,' ')"/>
								</center>
							</td>
							<td>
								<center>
									<xsl:variable name="PrioritySum">
										<xsl:call-template name="sumPriorities">
											<xsl:with-param name="Rows" select="//Row[substring-after(Assigned_x0020_To,'#') = $name]"/>
											<xsl:with-param name="Name" select="$name"/>
										</xsl:call-template>
									</xsl:variable>
									<xsl:value-of select="format-number($PrioritySum div count(//Row[substring-after(Assigned_x0020_To,'#') = $name]), '##.##')"/>
								</center>
							</td>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
	<xsl:template name="sumPriorities">
		<xsl:param name="Rows"/>
		<xsl:param name="Name"/>
		<xsl:param name="Index" select="1"/>
		<xsl:param name="Sum" select="0"/>
		<xsl:choose>
			<xsl:when test="$Rows[$Index]">
				<xsl:call-template name="sumPriorities">
					<xsl:with-param name="Rows" select="$Rows"/>
					<xsl:with-param name="Name" select="$Name"/>
					<xsl:with-param name="Index" select="$Index + 1"/>
					<xsl:with-param name="Sum" select="$Sum + substring($Rows[$Index]/Priority,2,1)"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$Sum"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="dogmar.xml" htmlbaseurl="" outputurl="" processortype="xalan" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="dogmar.xml" srcSchemaRoot="Rows" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition><template match="/"><block path="html/body/table/xsl:for&#x2D;each" x="253" y="141"/><block path="html/body/table/xsl:for&#x2D;each/tr/xsl:choose" x="213" y="141"/></template></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->