﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>

	<xsl:variable name="field_name_list"	select="document('field_list.xml')//field_list/field"/>
	<xsl:variable name="localization" select="document('localization.xml')/strings/group[@name='quarantine']/string"/>

	<xsl:template match="/">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<!-- header fields -->
		<tr>
			<xsl:for-each select="//record[1]/@*[name(.)!='filter_id']">
				<xsl:variable name="current_field_tag" select="name(.)"></xsl:variable>
				<xsl:variable name="current_field_name"	select="$field_name_list[@name=$current_field_tag]"></xsl:variable>
				<td>
					<xsl:attribute name="nowrap">
						nowrap
					</xsl:attribute>
					<xsl:attribute name="class">
						<xsl:choose>
							<xsl:when test="position() = last()">grey2-end</xsl:when>
							<xsl:otherwise>grey2</xsl:otherwise>	
						</xsl:choose>
					</xsl:attribute>
					<xsl:attribute name="id">
						<xsl:value-of select="$current_field_tag"/>
					</xsl:attribute>
					<xsl:choose>
						<xsl:when test="$current_field_tag='storage_entry_id'">
							<input type="checkbox" name="chkSelectAll" onclick="jsSelectAll();"/>
						</xsl:when>
						<xsl:otherwise>
							<a>
								<xsl:attribute name="href">
									javascript: jsToggleSort("<xsl:value-of select="$current_field_tag"/>")
								</xsl:attribute>	
								<xsl:choose>
									<xsl:when test="$current_field_name"><xsl:value-of select="$current_field_name"/></xsl:when>
									<xsl:otherwise><font color="red"><xsl:value-of select="$current_field_tag"/></font></xsl:otherwise>	
								</xsl:choose>
							</a>
						</xsl:otherwise>
					</xsl:choose>	
				</td>
			</xsl:for-each>	
		</tr>
	<!--/ heder fields -->
	<!-- content fields -->
		<xsl:for-each select="//record">
			<xsl:variable name="toggle"	select="boolean(position() mod 2)"/>
			<tr>
			<xsl:for-each select="@*[name(.)!='filter_id']">
				<xsl:variable name="current_field_tag" select="name(.)"></xsl:variable>
				<xsl:variable name="current_field_name"	select="$field_name_list[@name=$current_field_tag]"></xsl:variable>
				<td>
					<xsl:attribute name="class">
						<xsl:if test="$toggle and position()=last()">data1</xsl:if>
						<xsl:if test="$toggle and position()!=last()">data1b</xsl:if>
						<xsl:if test="not($toggle) and position()=last()">data2</xsl:if>
						<xsl:if test="not($toggle) and position()!=last()">data2b</xsl:if>
					</xsl:attribute>
					<xsl:apply-templates select="."/>
				</td>
			</xsl:for-each>
			</tr>
		</xsl:for-each>
	<!--/ content fields-->
	</table>
	</xsl:template>	

	<xsl:template match="record/@*">
		<xsl:call-template name="escape_special">
			<xsl:with-param name="value" select="."/>
		</xsl:call-template>
		<xsl:if test="normalize-space(.)=''"><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></xsl:if>
	</xsl:template>

	<xsl:template match="record/@*[name(.)='storage_entry_id']">
		<input type="checkbox" name="chkResendId" onclick="jsItems_Click(document.fmQMCmd.chkSelectAll, document.fmQMCmd.chkResendId, true);">
			<xsl:attribute name="value">
				<xsl:value-of select="."/>
			</xsl:attribute>
		</input>
	</xsl:template>
	
	<xsl:template match="record/@*[name(.)='filter_rule']">
			<xsl:value-of select="$localization[@name=concat('reason_', current()/../@filter_id)]"/>
			<xsl:call-template name="escape_special">
				<xsl:with-param name="value" select="../@filter_rule"/>
			</xsl:call-template>
	</xsl:template>
	
	<xsl:template match="record/@*[name(.)='storage_resend_count']">
		<xsl:if test=". > 0"><xsl:value-of select="$localization[@name='resent_status_true']"/></xsl:if>
		<xsl:if test=". = 0"><xsl:value-of select="$localization[@name='resent_status_false']"/></xsl:if>
	</xsl:template>
	
		<xsl:template name="escape_special">
		<xsl:param name="value"/>
		<xsl:choose>
			<xsl:when test="contains($value, ' ')"><xsl:call-template name="escape_quot"><xsl:with-param name="substr" select="$value"/></xsl:call-template></xsl:when>
			<xsl:otherwise><xsl:value-of select="$value"/></xsl:otherwise>
		</xsl:choose>	
	</xsl:template>
	
	<xsl:template name="escape_quot">
		<xsl:param name="substr"/>
		<xsl:choose>
			<xsl:when test="contains($substr, ' ')">
				<xsl:variable name="str_before_quot" select="substring-before($substr, ' ')"/>
				<xsl:variable name="str_after_quot" select="substring-after($substr, ' ')"/>
				<xsl:value-of select="$str_before_quot"/><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text><xsl:text/>	
				<xsl:call-template name="escape_quot">
					<xsl:with-param name="substr" select="$str_after_quot"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$substr"/>
			</xsl:otherwise>	
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>
