<?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>
					<style type="text/css">
						.vert
						{
							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:14px;
							margin:6px;
							height:300px;
							width:25px;
							bottom:0;
						}
						

						.row0 	{font-weight:normal;font-family:Arial;font-size:medium;height:200px;}
						.row1 	{width:450px;font-weight:normal;font-family:Arial;font-size:14px;}
						.rowx	{height:40px;vertical-align:center;}
						.cell0 	{width:24px;background-color:#4472C4;color:white;}
						.cell0_new {width:24px;background-color:yellow;}
						.cell1  {width:24px;background-color:#D9E1F2;text-align:center;}
						.cell1_new {width:24px;background-color:yellow;text-align:center;}
						.cellx1	{width:450px;font-weight:normal;font-family:Arial;font-size:14px;background-color:#4472C4;color:white;}
						.cellx2 {width:20px;font-weight:normal;font-family:Arial;font-size:14px;background-color:#D9E1F2;}
						.cellx1_new	{width:450px;font-weight:normal;font-family:Arial;font-size:14px;background-color:yellow;}
						.cellx2_new {width:20px;font-weight:normal;font-family:Arial;font-size:14px;background-color:yellow;}
						.cell_allowed {width:24px;background-color:#50C3B4;font-weight:normal;font-family:Arial;font-size:8px;text-align:center;}
						.cell_not_allowed {width:24px;background-color:#eeeeee;}
					</style>
				</head>
				<body>
					<p style="font-weight:normal;font-family:Arial;padding-left:4px;">SAHPRA Submission Type Matrix, Version <xsl:value-of select="//sub_type_vs_type/@version"/></p>
					<p style="font-weight:normal;font-family:Arial;padding-left:4px;">PLEASE NOTE !! If the submission type is not listed, the submission type cannot be grouped !! </p>
					<table bgcolor="#ffffff" border="0" cellpadding="8" cellspacing="4" >
						<tr class="row">
							<td style="width:450px;"></td>	
							<td style="width:20px;"><p class="vert">Submission Type-Short</p></td>	
							<xsl:for-each select="document('submission-type.xml')/code-definition/codes/item">						
								<xsl:variable name="jwcode">
									<xsl:value-of select="@code"/>
								</xsl:variable>								
								<xsl:if test="document('submission-type-matrix.xml')/sub_type_vs_type/item[@code=$jwcode]/@pairing!=''">
									<xsl:choose>
										<xsl:when test="contains(@valid-from-version,$jw_new_highlight)">
											<td class="cell0">
												<p class="vert">
													<xsl:value-of select="substring(@value,1,40)"/>
													<xsl:if test="substring(@value,41,1)">
														...
													</xsl:if>
												</p>
											</td>							
										</xsl:when>
										<xsl:otherwise>
											<td class="cell0">
												<p class="vert">
													<xsl:value-of select="substring(@value,1,40)"/>
													<xsl:if test="substring(@value,41,1)">
														...
													</xsl:if>
												</p>
											</td>							
										</xsl:otherwise>
									</xsl:choose>
								</xsl:if> <!-- -->
							</xsl:for-each>	
						</tr>
						<tr style="font-weight:normal;font-family:Arial;font-size:medium;height:10px;">
							<td class="row1">Submission Type-Long</td>	
							<td style="width:20px;"></td>	
							<xsl:for-each select="document('submission-type.xml')/code-definition/codes/item">						
								<xsl:variable name="jwcode">
									<xsl:value-of select="@code"/>
								</xsl:variable>								
								<xsl:if test="document('submission-type-matrix.xml')/sub_type_vs_type/item[@code=$jwcode]/@pairing!=''">
									<td class="cell1"><xsl:value-of select="substring(@code,10,0)"/></td>
									<!--(@code,10,2) changed to (@code,10,0) because of the long code name-->
								</xsl:if>
							</xsl:for-each>	
						</tr>
						<xsl:for-each select="document('submission-type.xml')/code-definition/codes/item">						
							<xsl:variable name="jwcode">
								<xsl:value-of select="@code"/>
							</xsl:variable>								
							<xsl:if test="document('submission-type-matrix.xml')/sub_type_vs_type/item[@code=$jwcode]/@pairing!=''">
								<tr class="rowx">
									<xsl:choose>
										<xsl:when test="contains(@valid-from-version,$jw_new_highlight)">
											<td class="cellx1_new"><xsl:value-of select="."/></td>	
										</xsl:when>
										<xsl:otherwise>
											<td class="cellx1"><xsl:value-of select="."/></td>	
										</xsl:otherwise>
									</xsl:choose>
									<td class="cellx2"><xsl:value-of select="substring(@code,10,0)"/></td>
									<!--(@code,10,2) changed to (@code,10,0) because of the long code name-->
									
									<xsl:variable name="jwtypecode">
										<xsl:value-of select="concat('A',substring(@code,10),'A')"></xsl:value-of>
									</xsl:variable>								
									<xsl:for-each select="document('submission-type.xml')/code-definition/codes/item">						
										<xsl:variable name="jwdesccode">
											<xsl:value-of select="@code"/>
										</xsl:variable>								
										<xsl:variable name="jwdesc">
											<xsl:value-of select="."/>
										</xsl:variable>								
										<xsl:variable name="jwtypecodeinmatrix"> 
											<xsl:value-of select="document('submission-type-matrix.xml')/sub_type_vs_type/item[@code=$jwdesccode]/@pairing"/>
										</xsl:variable>				
										<xsl:variable name="jwtypecodeinmatrix1"> 
											<xsl:value-of select="translate($jwtypecodeinmatrix,'|()','AAA')"/>
										</xsl:variable>				

							<xsl:variable name="jwcode1">
								<xsl:value-of select="@code"/>
							</xsl:variable>								

										<xsl:if test="document('submission-type-matrix.xml')/sub_type_vs_type/item[@code=$jwcode1]/@pairing!=''">
											<xsl:if test="contains($jwtypecodeinmatrix1,$jwtypecode)">
												<td class="cell_allowed">
													<xsl:attribute name="title"><xsl:value-of select="$jwdesc"></xsl:value-of></xsl:attribute>
													<xsl:value-of select="substring($jwdesccode,30)"></xsl:value-of>
													<!--Value has been changed from 15 to 30 because of spacing-->
													
												</td>							
											</xsl:if>
											<xsl:if test="contains($jwtypecodeinmatrix1,$jwtypecode) = false">
												<td class="cell_not_allowed"></td>							
											</xsl:if>
										</xsl:if>
									</xsl:for-each>	
								</tr>
							</xsl:if>
						</xsl:for-each>
					</table>
				</body>
			</html>
		</xsl:template>
	
</xsl:stylesheet>
