﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:import href="report_common.xslt"/>

	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

	<xsl:variable name="spam_cates_TMASE"			select="document('localization.xml')/strings/group[@name='SpamCate_TMASE']/string"/>
	<xsl:variable name="spam_cates_IMSSPOSTINI"		select="document('localization.xml')/strings/group[@name='SpamCate_IMSSPostini']/string"/>
	<xsl:variable name="report_strings"   			select="document('localization.xml')/strings/group[@name='report']/string"/>
	<xsl:variable name="activity"					select="$report_strings[@name='activity']"/>
	<xsl:variable name="sender"						select="$report_strings[@name='sender']"/>
	<xsl:variable name="domain"						select="$report_strings[@name='domain']"/>
	<xsl:variable name="recipient"					select="$report_strings[@name='recipient']"/>
	<xsl:variable name="frequency"					select="$report_strings[@name='frequency']"/>
	<xsl:variable name="percentage"					select="$report_strings[@name='percentage']"/>
	<xsl:variable name="spam_detected_count"		select="$report_strings[@name='spam_detected_count']"/>
	<xsl:variable name="phish_detected_count"		select="$report_strings[@name='phish_detected_count']"/>
	<xsl:variable name="false_positive_count"		select="$report_strings[@name='false_positive_count']"/>
	<xsl:variable name="total_message_count"		select="$report_strings[@name='total_message_count']"/>
	<xsl:variable name="ers_count"		select="$report_strings[@name='ers_count']"/>
  
	<xsl:template match="data[@name='report_item_spam_summary']">
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="border">
			<thead>
				<tr>
					<td class="tableheader" colspan="4"><xsl:value-of select="$localization[@name=current()/@name]"/></td>
				</tr>
				<tr>
					<td class="grey" width="38%"><xsl:value-of select="$activity"   /></td>
					<td class="grey" width="20%" align="right"><xsl:value-of select="$frequency"  /></td>
					<td class="grey-end" width="20%" align="right"><xsl:value-of select="$percentage" /></td>
					<td class="grey-end"        ><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td class="data1b"><xsl:value-of select="$total_message_count"/></td>
					<td class="data1b" align="right"><xsl:value-of select="datarow/@total_message_count"/></td>
					<td class="data1"><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
					<td class="data1" ><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
				</tr>
				<tr>
					<td class="data2b"><xsl:text disable-output-escaping="yes">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</xsl:text>
						<xsl:value-of select="$spam_detected_count"/></td>
					<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="datarow/@spam_detected_count"/></xsl:call-template></td>
					<td class="data2" align="right">
						<xsl:call-template name="format_percentage">
							<xsl:with-param name="numerator" select="datarow/@spam_detected_count"/>
							<xsl:with-param name="denominator" select="datarow/@total_message_count"/></xsl:call-template></td>
					<td class="data2" ><xsl:value-of select="$localization[@name='of_scaned_total']"/></td>
				</tr>
				<tr>
					<td class="data1b"><xsl:text disable-output-escaping="yes">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</xsl:text>
						<xsl:value-of select="$phish_detected_count"/></td>
					<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="datarow/@phish_detected_count"/></xsl:call-template></td>
					<td class="data1" align="right">
						<xsl:call-template name="format_percentage">
							<xsl:with-param name="numerator" select="datarow/@phish_detected_count"/>
							<xsl:with-param name="denominator" select="datarow/@total_message_count"/></xsl:call-template></td>
					<td class="data1" ><xsl:value-of select="$localization[@name='of_scaned_total']"/></td>
				</tr>
        <xsl:variable name="false_positive_count_exist"		select="boolean(datarow/@false_positive_count)"/>
				<xsl:if test="$false_positive_count_exist">
				<tr>
					<td class="data2b"><xsl:text disable-output-escaping="yes">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</xsl:text>
						<xsl:value-of select="$false_positive_count"/></td>
					<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="datarow/@false_positive_count"/></xsl:call-template></td>
					<td class="data2" align="right">
						<xsl:call-template name="format_percentage">
							<xsl:with-param name="numerator" select="datarow/@false_positive_count"/>
							<xsl:with-param name="denominator" select="datarow/@spam_detected_count"/></xsl:call-template></td>
					<td class="data2" ><xsl:value-of select="$localization[@name='of_spams_detected']"/></td>
				</tr>
				</xsl:if>
				<xsl:if test="$pr_ers != 'FS_HIDE'">
					<tr>
						<td class="data1b"><xsl:value-of select="$ers_count"/></td>
						<td class="data1b" align="right"><xsl:value-of select="datarow/@ers_count"/></td>
						<td class="data1"><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
						<td class="data1" ><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
					</tr>
				</xsl:if>
			</tbody>
		</table>
	</xsl:template>


	<!--xsl:template match="data[@name='report_item_spam_top_sender']">
	</xsl:template>

	<xsl:template match="data[@name='report_item_spam_top_domain']">
	</xsl:template>

	<xsl:template match="data[@name='report_item_spam_top_false_positive_sender']">
	</xsl:template>

	<xsl:template match="data[@name='report_item_spam_top_false_positive_domain']">
	</xsl:template-->

	<xsl:template match="data[@name='report_item_spam_categories']">
		<xsl:call-template name="format-AS-categories">
			<xsl:with-param name="data-nodes" select="datarow[starts-with(@categories, 'AS_CAT_')]"/>
		</xsl:call-template>
		<xsl:if test="datarow[not(starts-with(@categories, 'AS_CAT_'))]">
			<xsl:call-template name="format-POSTINI-categories">
				<xsl:with-param name="data-nodes" select="datarow[not(starts-with(@categories, 'AS_CAT_'))]"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="format-AS-categories">
		<xsl:param name="data-nodes"/>
		<xsl:variable name="total_count" select="sum($data-nodes/@spam_count)"/>
		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="border">
			<thead>
				<tr>
					<td class="tableheader" colspan="3"><xsl:value-of select="$localization[@name=current()/@name]"/></td>
				</tr>
				<tr>
					<td class="grey"><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
					<td class="grey" align="right"><xsl:value-of select="$localization[@name='frequency']"/></td>
					<td class="grey-end" align="right"><xsl:value-of select="$localization[@name='percentage_of_spam_detected']"/></td>
				</tr>
			</thead>
			<tbody>
			<xsl:for-each select="$data-nodes">
				<tr><td><xsl:attribute name="class">data<xsl:value-of select="((position()+1) mod 2) + 1"/>b</xsl:attribute>
						<xsl:value-of select="$spam_cates_TMASE[@name=current()/@categories]"/></td>
					<td align="right"><xsl:attribute name="class">data<xsl:value-of select="((position()+1) mod 2) + 1"/>b</xsl:attribute>
						<xsl:value-of select="@spam_count"/></td>
					<td align="right"><xsl:attribute name="class">data<xsl:value-of select="((position()+1) mod 2) + 1"/></xsl:attribute>
						<xsl:call-template name="format_percentage">
							<xsl:with-param name="numerator" select="@spam_count"/>
							<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td></tr>
			</xsl:for-each>
			</tbody>
		</table>
	</xsl:template>
	
	<xsl:template name="format-POSTINI-categories">
		<xsl:param name="data-nodes"/>

		<xsl:variable name="Default_Triggered"		select="$spam_cates_IMSSPOSTINI[@name='Default_Triggered']"/>
		<xsl:variable name="Blocklist_Triggered"	select="$spam_cates_IMSSPOSTINI[@name='Blocklist_Triggered']"/>
		<xsl:variable name="Porn"					select="$spam_cates_IMSSPOSTINI[@name='Porn']"/>
		<xsl:variable name="Racist"					select="$spam_cates_IMSSPOSTINI[@name='Racist']"/>
		<xsl:variable name="Commercial"				select="$spam_cates_IMSSPOSTINI[@name='Commercial']"/>
		<xsl:variable name="MMF"		 			select="$spam_cates_IMSSPOSTINI[@name='MMF']"/>
		<xsl:variable name="LeastConfident"			select="$spam_cates_IMSSPOSTINI[@name='LeastConfident']"/>
		<xsl:variable name="Confident" 				select="$spam_cates_IMSSPOSTINI[@name='Confident']"/>
		<xsl:variable name="VeryConfident" 			select="$spam_cates_IMSSPOSTINI[@name='VeryConfident']"/>
		<xsl:variable name="MostConfident" 			select="$spam_cates_IMSSPOSTINI[@name='MostConfident']"/>
		
		<xsl:variable name="total_count" select="sum($data-nodes/@spam_count)"/>

		<table width="100%" border="0" cellpadding="0" cellspacing="0" class="border">
			<thead>
				<tr>
					<td colspan="4"></td>
				</tr>
				<tr>
					<td class="tableheader" colspan="4"><xsl:value-of select="$localization[@name=current()/@name]"/></td>
				</tr>
				<xsl:call-template name="report_category_heading"/>
			</thead>
			<tbody>
				<tr>
					<td class="data1b" colspan="2"><xsl:value-of select="$Default_Triggered"/></td>
					<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Default_Triggered']/@spam_count"/></xsl:call-template></td>
					<td class="data1"  align="right">
						<xsl:call-template name="format_percentage">
							<xsl:with-param name="numerator" select="$data-nodes[@categories='Default_Triggered']/@spam_count"/>
							<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
				</tr>
				<tr>
					<td class="data2b" colspan="2"><xsl:value-of select="$Blocklist_Triggered"/></td>
					<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Blocklist_Triggered']/@spam_count"/></xsl:call-template></td>
					<td class="data2"  align="right">
						<xsl:call-template name="format_percentage">
							<xsl:with-param name="numerator" select="$data-nodes[@categories='Blocklist_Triggered']/@spam_count"/>
							<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>

				</tr>
				<xsl:call-template name="report_category_heading"/>
				<tr>
					<td class="data1b" colspan="2"><xsl:value-of select="$Porn"/></td>
					<td class="data1b"></td>
					<td class="data1"></td>
				</tr>
							<tr>
								<td class="data2b"></td>
								<td class="data2b"><xsl:value-of select="$MostConfident"/></td>
								<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Porn_MostConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data2"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Porn_MostConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data1b"></td>
								<td class="data1b"><xsl:value-of select="$VeryConfident"/></td>
								<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Porn_VeryConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data1"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Porn_VeryConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data2b"></td>
								<td class="data2b"><xsl:value-of select="$Confident"/></td>
								<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Porn_Confident']/@spam_count"/></xsl:call-template></td>
								<td class="data2"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Porn_Confident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data1b"></td>
								<td class="data1b"><xsl:value-of select="$LeastConfident"/></td>
								<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Porn_LeastConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data1"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Porn_LeastConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
				<xsl:call-template name="report_category_heading"/>
				<tr>
					<td class="data1b" colspan="2"><xsl:value-of select="$Racist"/></td>
					<td class="data1b"></td>
					<td class="data1" ></td>
				</tr>
							<tr>
								<td class="data2b"></td>
								<td class="data2b"><xsl:value-of select="$MostConfident"/></td>
								<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Racist_MostConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data2"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Racist_MostConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data1b"></td>
								<td class="data1b"><xsl:value-of select="$VeryConfident"/></td>
								<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Racist_VeryConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data1"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Racist_VeryConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data2b"></td>
								<td class="data2b"><xsl:value-of select="$Confident"/></td>
								<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Racist_Confident']/@spam_count"/></xsl:call-template></td>
								<td class="data2"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Racist_Confident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data1b"></td>
								<td class="data1b"><xsl:value-of select="$LeastConfident"/></td>
								<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Racist_LeastConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data1"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Racist_LeastConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
				<xsl:call-template name="report_category_heading"/>
				<tr>
					<td class="data1b" colspan="2"><xsl:value-of select="$Commercial"/></td>
					<td class="data1b"></td>
					<td class="data1"></td>
				</tr>
							<tr>
								<td class="data2b"></td>
								<td class="data2b"><xsl:value-of select="$MostConfident"/></td>
								<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Commercial_MostConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data2"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Commercial_MostConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data1b"></td>
								<td class="data1b"><xsl:value-of select="$VeryConfident"/></td>
								<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Commercial_VeryConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data1"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Commercial_VeryConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data2b"></td>
								<td class="data2b"><xsl:value-of select="$Confident"/></td>
								<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Commercial_Confident']/@spam_count"/></xsl:call-template></td>
								<td class="data2"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Commercial_Confident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data1b"></td>
								<td class="data1b"><xsl:value-of select="$LeastConfident"/></td>
								<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='Commercial_LeastConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data1"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='Commercial_LeastConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
				<xsl:call-template name="report_category_heading"/>
				<tr>
					<td class="data1b" colspan="2"><xsl:value-of select="$MMF"/></td>
					<td class="data1b"></td>
					<td class="data1"></td>
				</tr>
							<tr>
								<td class="data2b"></td>
								<td class="data2b"><xsl:value-of select="$MostConfident"/></td>
								<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='MMF_MostConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data2"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='MMF_MostConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data1b"></td>
								<td class="data1b"><xsl:value-of select="$VeryConfident"/></td>
								<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='MMF_VeryConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data1"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='MMF_VeryConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data2b"></td>
								<td class="data2b"><xsl:value-of select="$Confident"/></td>
								<td class="data2b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='MMF_Confident']/@spam_count"/></xsl:call-template></td>
								<td class="data2"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='MMF_Confident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
							<tr>
								<td class="data1b"></td>
								<td class="data1b"><xsl:value-of select="$LeastConfident"/></td>
								<td class="data1b" align="right"><xsl:call-template name="format_number"><xsl:with-param name="num" select="$data-nodes[@categories='MMF_LeastConfident']/@spam_count"/></xsl:call-template></td>
								<td class="data1"  align="right">
									<xsl:call-template name="format_percentage">
										<xsl:with-param name="numerator" select="$data-nodes[@categories='MMF_LeastConfident']/@spam_count"/>
										<xsl:with-param name="denominator" select="$total_count"/></xsl:call-template></td>
							</tr>
			</tbody>
		</table>
	</xsl:template>
	
	<xsl:template name="report_category_heading">
		<tr>
			<td class="grey" colspan="2"><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text></td>
			<td class="grey" align="right">Frequency</td>
			<td class="grey-end" align="right">Percentage of spam detected from IMSS</td>
		</tr>
	</xsl:template>

</xsl:stylesheet>
