<?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:template match="/">
		<xsl:apply-templates select="results"/>
	</xsl:template>
	
	<xsl:template match="results" >
		<html>
			<head/>
			<body>
						<center>
							<h1><xsl:value-of select="@name"/></h1>
							<br />
							<table border="1" cellspacing="0" cellpadding="0">
								<tr>
									<th>Question</th>
									<th>Correct Answer</th>
									<th>Results</th>
								</tr>
								<xsl:for-each select="*">
									<tr border="2">
										<td>
											<xsl:choose>
												<xsl:when test="string-length(substring-before(name(.),'3Q3')) != string-length(name(.)) and
												string-length(substring-before(name(.),'3Q3')) > 0">
													<xsl:value-of select="translate(concat(substring-before(name(.),'3Q3'),'?'),'_',' ')"/>
												</xsl:when>
												<xsl:otherwise>
													<xsl:value-of select="translate(name(.),'_',' ')"/>
												</xsl:otherwise>
											</xsl:choose>
										</td>
										<td>
											<xsl:value-of select="@answer"/>
										</td>
										<td height="100%">
											<table border="1" height="100%" width="100%" cellpadding="0" cellspaing="0">
												<xsl:for-each select="./*">
													<xsl:variable name="curr">
														<xsl:value-of select="."/>
													</xsl:variable>
													<xsl:variable name="totalanswers">
														<xsl:value-of select="../totalanswers"/>
														</xsl:variable>
													<xsl:variable name="width">
														<xsl:value-of select="($curr div $totalanswers) * 100"/>
													</xsl:variable>
						
													<xsl:if test="name(.) != 'totalanswers'">
														<tr>
															<td>
																<xsl:choose>
																	<xsl:when test="name(.) != 'numcorrectanswers'">
																		<xsl:value-of select="translate(substring(name(.),2),'-',' ')"/>
																	</xsl:when>
																	<xsl:otherwise>
																		Correct Answers
																	</xsl:otherwise>
																</xsl:choose>
															</td>
										
															<td>
																<table  height="100%" cellpadding="0" cellspacing="0">
																	<tr>
																		<td bgcolor="#00AA00" width="{$width}">
																		</td>
										
																		<td>
																			<xsl:value-of select="floor($width)"/>%
																		</td>
																	</tr>
																</table>
															</td>
														</tr>
													</xsl:if>
												</xsl:for-each>
											</table>
										</td>
									</tr>
								</xsl:for-each>
							</table>
						</center>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>