<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:output method="html"/>
	<!-- Get URL used to link to each record (this URL would be provided in XML by the business object -->
	<xsl:variable name="URL" select="BusinessObject/@URL"/>
	<xsl:template match="/">
		<xsl:apply-templates select="BusinessObject"/>
	</xsl:template>
	
	<!-- parameter for the column to be sorted by -->
	<xsl:param name="Column">Dummy</xsl:param>	
	
	<!-- Primary template to descend down into XML provided by business object -->
	<!-- HTML elements are provided here to begin building the HTML page to be generated by the transformation -->
	<xsl:template match="BusinessObject">							
			
		<h1><xsl:value-of select="@Title"/></h1>
		<br/>		
				
		<table>
			<!-- Add column headers to table 				-->
				<xsl:apply-templates select="ColumnHeaders"/>
			<!-- Add detail information to table			-->
				<xsl:apply-templates select="Rows"/>				
		</table>
		<BR/>			
			
	</xsl:template>
	
	<!-- This template builds the column header (labels) based on information submitted by the business object -->
	<xsl:template match="ColumnHeaders">
		<tr bgcolor="#333399" fgcolor="#FFFFFF">
		  <xsl:for-each select="Column">
			<th class="Item" width="200">	
		         <font color="white">				
			     <xsl:value-of select="@Name"/>	
			   </font>										
			</th>
		  </xsl:for-each>		
		</tr>
	</xsl:template>
	
	<!-- This template gets each row/record from the business object -->
	<xsl:template match="Rows">					
		<xsl:for-each select="Row">					
			<tr bgcolor="#CDEDFF">							
				<xsl:apply-templates select="Cols">
					<xsl:with-param name="ObjID" select="@ObjectID"/>
				</xsl:apply-templates>				
			</tr>
		</xsl:for-each>
	</xsl:template>
	
	<!-- This template matches the columns and places them inside of table cells (td) -->
	<xsl:template match="Cols">
			<xsl:param name="ObjID"/>
			<xsl:for-each select="Col">
				<td>
				<xsl:choose>
					<xsl:when test="position()=1">
			<!-- Build a link for this item based upon URL captured above, and record ID passed as a parameter -->		
			<a>
				<xsl:attribute name="href"><xsl:value-of select="$URL"/>?ID=<xsl:value-of select="$ObjID"/></xsl:attribute>
				<xsl:value-of select="@value"/>
			</a>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="@value"/>
					</xsl:otherwise>
				</xsl:choose>			
				</td>
			</xsl:for-each>			
	</xsl:template>
<!-- End of XSL Template -->
</xsl:stylesheet>

