<?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" encoding="UTF-8" indent="no" />
	<xsl:variable name="jw_new_highlight">
		<xsl:value-of select="3.0" />
	</xsl:variable>
	<xsl:template match="/">
		<html>
			<head>

				<!-- Use lastest version of Internet Explorer -->
				<meta http-equiv="X-UA-Compatible" content="IE=edge" />

				<style type="text/css">
					.vert
					{
					display:block;
					-ms-transform: rotate(-90.0deg);  /* IE9+ */
					-webkit-transform:rotate(-90deg) translate(0%, 87%);
					-moz-transform:rotate(-90deg) translate(0%, 87%);
					-o-transform: rotate(-90deg);
					transform: rotate(-90deg) translate(0%, 87%);
					-webkit-transform-origin: 40% 90%;
					-moz-transform-origin: 40% 90%;
					transform-origin: 40% 90%;
					white-space:nowrap;
					font-weight:normal;font-family:Arial;font-size:18px;
					margin:6px;
					height:400px;
					width:20px;
					bottom:0;
					}
					.vert0
					{
					display:block;
					-webkit-transform:rotate(-90deg) translate(0%, 87%);
					-moz-transform:rotate(-90deg) translate(0%, 87%);
					-o-transform: rotate(-90deg);
					transform: rotate(-90deg) translate(0%, 87%);
					-webkit-transform-origin: 40% 90%;
					-moz-transform-origin: 40% 90%;
					transform-origin: 40% 90%;
					white-space:nowrap;
					font-weight:normal;font-family:Arial;font-size:16px;
					margin:6px;
					height:14px;
					width:14px;
					bottom:0;
					}
					.vertk
					{
					display:block;
					-ms-transform: rotate(-90.0deg);  /* IE9+ */
					-webkit-transform:rotate(-90deg) translate(0%, 87%);
					-moz-transform:rotate(-90deg) translate(0%, 87%);
					-o-transform: rotate(-90deg);
					transform: rotate(-90deg) translate(0%, 87%);
					-webkit-transform-origin: 40% 90%;
					-moz-transform-origin: 40% 90%;
					transform-origin: 40% 90%;
					white-space:nowrap;
					font-weight:normal;font-family:Arial;font-size:18px;
					margin:6px;
					height:0px;
					width:0px;
					bottom:0;
					}

					.vector {background-color:#00ff00;}
					.vector1 {font-weight:normal;background-color:#00bb00;font-family:Arial;font-size:14px;}
					.vector2 {font-weight:normal;font-family:Arial;font-size:14px;}
					.vector3
					{background-color:#00ccff;font-family:Arial;font-weight:normal;font-size:18px;color:black;vertical-align:top;;text-align:center}
					.vector4
					{font-weight:normal;font-family:Arial;font-size:medium;height:20px;vertical-align:top;}
					.vector5 {background-color:white;}
					.vector6 {background-color:#E2F3FB;}
					.vector7 {width:24px;background-color:#ffff;text-align:bottom;color:black}

					table.sticky-table thead tr th {
					font-weight: normal;
					outline: 2px solid #fff;
					position: sticky;
					top: 0;
					z-index: 2;
					}
					table.sticky-table tbody tr td:first-child,
					table.sticky-table tbody tr td:nth-child(2) {
					position: sticky;
					z-index: 1;
					}
					table.sticky-table tbody tr td:first-child {
					left: 0;
					}
					table.sticky-table tbody tr td:nth-child(2) {
					left: 216px;
					}

					.cell0 {width:50px;background-color:#0044AD;text-align:center;color:white}
					.cellx {width:24px;background-color:#eeeeee;text-align:center;}
					.cell0_new {width:24px;background-color:yellow;text-align:center;}
					.row {font-weight:normal;font-family:Arial;font-size:medium;height:200px;}
					.rowx {font-weight:normal;font-family:Arial;font-size:14px;}
					.error
					{background-color:#eeeeee;font-family:Arial;font-weight:bold;font-size:18px;color:red;vertical-align:top;}
					.xe-error
					{background-color:#eeeeee;font-family:Arial;font-weight:bold;font-size:16px;color:brown;vertical-align:top;}
					.warning
					{background-color:#eeeeee;font-family:Arial;font-weight:bold;font-size:18px;color:orange;vertical-align:top;}
					.xw-warning
					{background-color:#eeeeee;font-family:Arial;font-weight:bold;font-size:16px;color:orange;vertical-align:top;}
					.possible
					{background-color:#eeeeee;font-family:Arial;font-weight:bold;font-size:18px;color:#aaaaff;vertical-align:top;}
					.nv
					{background-color:#eeeeee;font-family:Arial;font-weight:normal;font-size:12px;color:gray;vertical-align:top;}
					.nv-legend
					{background-color:#eeeeee;font-family:Arial;font-weight:normal;font-size:18px;color:gray;vertical-align:top;}
					.leftheader {background-color:#dddddd;}
					.leftheader_new {background-color:#50C3b4;}
					.table {bgcolor="blue"}
					.legend {font-weight:normal;font-family:Arial;font-size:14px;}
					.legend_col1{style=width:40px;}
				</style>
			</head>
			<body>
				<p style="font-weight:normal;font-family:Arial;padding-left:4px;">SAHPRA Document Matrix -
					Version <xsl:value-of select="//sub_type_vs_toc/@version" /></p>

				<table class="table" border="0" cellpadding="8" cellspacing="4">
					<tr class="vector4">
					</tr>
				</table>

				<table class="table sticky-table" border="0" cellpadding="8" cellspacing="4">
					<thead>
						<tr class="row">
							<th class="cell0">Section<p class="vert"></p></th>
							<th class="cell0">Section Title<p class="vert"></p></th>

							<xsl:for-each
								select="document('submission-type.xml')/code-definition/codes/item/@value">
								<xsl:if test="count(../@valid-to-version)=0">
									<xsl:choose>
										<xsl:when test="contains(../@valid-from-version,$jw_new_highlight)">
											<th class="cell0_new">
												<p class="vert">
													<xsl:value-of select="substring(.,1,40)" />
													<xsl:if test="substring(.,41,1)">
														...
													</xsl:if>
												</p>
											</th>
										</xsl:when>
										<xsl:otherwise>
											<th class="cell0">
												<p class="vert">
													<xsl:value-of select="substring(.,1,40)" />
													<xsl:if test="substring(.,41,1)">
														...
													</xsl:if>
												</p>
											</th>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:if>
							</xsl:for-each>
						</tr>
					</thead>
					<xsl:apply-templates />
				</table>
				
				<div>
					<p />
					<table class="legend">
						<tr>
							<td class="error" width="50">E</td>
							<td class="error" width="200">Error</td>
							<td style="width:450px;background-color:#eeeeee;">The document is required in the
								sequence being submitted. If no document is present, it will lead to a validation
								error and the sequence being rejected.</td>
						</tr>
						<tr>
							<td class="warning" width="50">W</td>
							<td class="warning" width="200">Warning</td>
							<td style="width:450px;background-color:#eeeeee;">The document is expected in the
								sequence. If no document is present, it will lead to a warning and could possibly
								lead to the sequence being rejected.</td>
						</tr>
						<tr>
							<td class="possible" width="50">P</td>
							<td class="possible" width="200">Possible</td>
							<td style="width:450px;background-color:#eeeeee;">The document is required in certain
								circumstances for the particular sequence type, but not all. A list of the sections
								where content has been provided will be created by the validator for review purposes
								in content screening. The absence of a required document could lead to the sequence
								being rejected.</td>
						</tr>
						<tr>
							<td class="xe-error" width="50">XE</td>
							<td class="xe-error" width="200">Excluded: Error</td>
							<td style="width:450px;background-color:#eeeeee;">The document is not allowed for the
								particular Submission Type and will result in an Error if included.</td>
						</tr>
						<tr>
							<td class="xw-warning" width="50">XW</td>
							<td class="xw-warning" width="200">Excluded: Warning</td>
							<td style="width:450px;background-color:#eeeeee;">The document is not expected for the
								particular Submission Type and will result in a Warning if included.</td>
						</tr>
						<tr>
							<td class="nv" width="50">NV</td>
							<td class="nv-legend" width="200">Not Validated</td>
							<td style="width:450px;background-color:#eeeeee;">The presence or absence of the
								document is not checked in the electronic validation of the particular Sequence
								Type.</td>
						</tr>
						<tr>
							<td class="nv" width="50"></td>
							<td class="nv-legend" width="200">Not Yet Defined</td>
							<td style="width:450px;background-color:#eeeeee;">Not yet planned within the scope of
								the eCTD.</td>
						</tr>
					</table>
				</div>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="sub_type_vs_toc/*">
		<tr class="rowx">
			<xsl:choose>
				<xsl:when test="@header='yes'">
					<td class="leftheader_new">
						<p style="width:20px;text-align:center;">
							<xsl:value-of select="@number" />
						</p>
					</td>
					<td class="leftheader_new">
						<p style="width:350px;">
							<xsl:value-of select="@name" />
						</p>
					</td>
				</xsl:when>
				<xsl:otherwise>
					<td class="leftheader">
						<p style="width:200px;text-align:center;">
							<xsl:value-of select="@number" />
						</p>
					</td>
					<td class="leftheader">
						<p style="width:550px;">
							<xsl:value-of select="@name" />
						</p>
					</td>
				</xsl:otherwise>
			</xsl:choose>

			<xsl:for-each select="subType">
				<xsl:variable name="subCodeForTooltip">
					<xsl:value-of select='@code' />
				</xsl:variable>
				<td class="cellx">
					<xsl:attribute name="Title">
						<xsl:value-of
							select="document('submission-type.xml')/code-definition/codes/item[@code=$subCodeForTooltip]/@value" />
					</xsl:attribute>
					<xsl:call-template name="content">
						<xsl:with-param name="content_flag" select="@content" />
					</xsl:call-template>
				</td>
			</xsl:for-each>


		</tr>
	</xsl:template>

	<xsl:template name="content">
		<xsl:param name="content_flag" />
		<xsl:choose>
			<xsl:when test="$content_flag='E'">
				<font class="error">
					<xsl:value-of select="$content_flag" />
				</font>
			</xsl:when>
			<xsl:when test="$content_flag='W'">
				<font class="warning">
					<xsl:value-of select="$content_flag" />
				</font>
			</xsl:when>
			<xsl:when test="$content_flag='P'">
				<font class="possible">
					<xsl:value-of select="$content_flag" />
				</font>
			</xsl:when>
			<xsl:when test="$content_flag='XE'">
				<font class="xe-error">
					<xsl:value-of select="$content_flag" />
				</font>
			</xsl:when>
			<xsl:when test="$content_flag='XW'">
				<font class="xw-warning">
					<xsl:value-of select="$content_flag" />
				</font>
			</xsl:when>
			<xsl:when test="$content_flag='NV'">
				<font class="nv">
					<xsl:value-of select="$content_flag" />
				</font>
			</xsl:when>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>
