<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:script><![CDATA[
	var firstTime = true;
	var prevVendor = "";
	var subTotal = 0.00;
	var maxTotal = 0.00;
	
	var isOddrow = false;
	function checkRow() 
	{
		isOddrow = !isOddrow;
		if (isOddrow == true) 
			return "oddrow";
		else
			return "evenrow";
	}

	function init(node)
	{
		prevVendor = node.getAttribute('vendor');
		
		return prevVendor;
	}
	
	function controlBreak(node)
	{
		var currVendor = node.getAttribute('vendor');
		var currPrice  = parseFloat(node.getAttribute('totalPrice'));
		
		if (firstTime == true)
		{
			init(node);
			firstTime = false;
		}
		
		if (prevVendor != currVendor)
		{
			if (subTotal > maxTotal) maxTotal = subTotal;
			return true;
		}
		else
		{
			subTotal += currPrice;
			return false;
		}
	}
	
	function setnewVendor(node)
	{
		var currVendor = node.getAttribute('vendor');
		var currPrice  = parseFloat(node.getAttribute('totalPrice'));
		prevVendor = currVendor;
		subTotal = currPrice;
	}	
]]></xsl:script>

<xsl:template match="/">
	<xsl:apply-templates select="DVDDATA/DVDLIST"/>
</xsl:template>

<xsl:template match="DVDDATA/DVDLIST">
	<TABLE border="0">

	<xsl:for-each select="DVD" order-by="@vendor">
		<xsl:if expr="controlBreak(this)">
			<TR>
			<xsl:attribute name="class"><xsl:eval>checkRow()</xsl:eval></xsl:attribute>			
			<TD class="fieldtitle"><xsl:eval>prevVendor</xsl:eval></TD>
			<TD><xsl:eval>formatNumber(subTotal, "$0.00")</xsl:eval>
			<DIV>
			<xsl:attribute name="STYLE">
			width: <xsl:eval>parseInt(subTotal)</xsl:eval>;
			background-color: #AFC9FF;
			border-color: #000000; 
			border-width: thin; 
			border-style: dashed;
			</xsl:attribute>
			</DIV>
			</TD>
  			</TR>

			<xsl:eval>setnewVendor(this)</xsl:eval>
		</xsl:if>
	</xsl:for-each>

	<TR>
	<xsl:attribute name="class"><xsl:eval>checkRow()</xsl:eval></xsl:attribute>
	<TD class="fieldtitle"><xsl:eval>prevVendor</xsl:eval></TD>
	<TD><xsl:eval>formatNumber(subTotal, "$0.00")</xsl:eval>
	<BR/>
	<DIV>
	<xsl:attribute name="STYLE">
	width: <xsl:eval>parseInt(subTotal)</xsl:eval>;
	background-color: #AFC9FF;
	border-color: #000000; 
	border-width: thin; 
	border-style: dashed;
	</xsl:attribute>
	</DIV>
	</TD>
	</TR>
	</TABLE>
</xsl:template>

</xsl:stylesheet>

