<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--   MAIN Template         -->	
	<xsl:template match="/">
		<xsl:variable name="redWireConfigFile">../configRedWireDCC.xml</xsl:variable>
		<html>
		<head>
			<xsl:call-template name="Header">
				<xsl:with-param name="configRedWire"><xsl:value-of select="$redWireConfigFile"/></xsl:with-param>
			</xsl:call-template>
		<script type="text/javascript">
		var delayForEachMessage = 1000
		var pausecontent=new Array()
			<xsl:apply-templates select="RedWire">
				<xsl:with-param name="configRedWire"><xsl:value-of select="$redWireConfigFile"/></xsl:with-param>
			</xsl:apply-templates>
		</script>
		</head>
		<body scroll="auto" border="0">
		<script type="text/javascript">
		new pausescroller(pausecontent,"EmailDiagFilRougeScroller","someclass",delayForEachMessage);
		</script>
		</body>
		</html>

	</xsl:template>

<!-- Config redWire -->
<xsl:template name="Header">
	<xsl:param name="configRedWire"/>
	<xsl:apply-templates select="document($configRedWire)//DDCConfigRedWire//Ressource-file[Id = 'RedWireCSS_AP']">
		 <xsl:with-param name="paramCSSOrJS">CSS</xsl:with-param>
	 </xsl:apply-templates>	 
	<xsl:apply-templates select="document($configRedWire)//DDCConfigRedWire//Ressource-file[Id = 'RedWireJS_AP']">
		 <xsl:with-param name="paramCSSOrJS">JS</xsl:with-param>
 	</xsl:apply-templates>
</xsl:template>  

  
<xsl:template match="Ressource-file">
	<xsl:param name="paramCSSOrJS"/>
	<!-- CSS -->
	<xsl:if test="$paramCSSOrJS = 'CSS'">
		<link href="{Location}" rel="stylesheet" type="text/css"></link>
	</xsl:if>

	<!-- JS -->
	<xsl:if test="$paramCSSOrJS = 'JS'">
		<script type="text/JavaScript" src="{Location}"></script>
	</xsl:if>
</xsl:template>


<xsl:template name="PicturePath">
	<xsl:param name="alertLevel"/>
	<xsl:param name="configRedWire"/>
	<xsl:value-of select="document($configRedWire)//DDCConfigRedWire//Ressource-file[Id = $alertLevel]/Location"/>
</xsl:template>	

<!-- End Config Red Wire -->


<!-- RedWire Template -->
<xsl:template match="RedWire">
	<xsl:param name="configRedWire"/>
	<!-- ALERT -->
	<!-- definir chemin de l'image 'Alert' -->
	<!-- {/DDCConfigRedWire/PicturesPathName/PicturesError -->
	<xsl:variable name="pictureAlert">
		<xsl:call-template name="PicturePath">
			<xsl:with-param name="alertLevel">Error</xsl:with-param>
			<xsl:with-param name="configRedWire"><xsl:value-of select="$configRedWire"/></xsl:with-param>
		</xsl:call-template>	
	</xsl:variable>
	
	<xsl:call-template name="traitementAlert">
		<xsl:with-param name="nb" select="0"/>
		<xsl:with-param name="imgPath"> <xsl:value-of select="$pictureAlert"/> </xsl:with-param>
	</xsl:call-template> 

	<xsl:variable name="nbAlert"> <xsl:value-of select="count(Message[AlertLevel[.='1']])"/> </xsl:variable>
	
	<!-- WARNING -->
	<!-- definir chemin de l'image 'Warning' -->
	<!-- {/DDCConfigRedWire/PicturesPathName/PicturesWarn -->
	<xsl:variable name="pictureWarn">
		<xsl:call-template name="PicturePath">
			<xsl:with-param name="alertLevel">Warn</xsl:with-param>
			<xsl:with-param name="configRedWire"><xsl:value-of select="$configRedWire"/></xsl:with-param>			
		</xsl:call-template>	
	</xsl:variable>

	<xsl:call-template name="traitementWarning">
		<xsl:with-param name="nb" select="nbAlert"/>
		<xsl:with-param name="imgPath"> <xsl:value-of select="$pictureWarn"/> </xsl:with-param>
	</xsl:call-template> 

	<xsl:variable name="nbWarning"> <xsl:value-of select="count(Message[AlertLevel[.='2']])"/> </xsl:variable>

	<!-- INFO -->
	<!-- definir chemin de l'image 'Info' -->
	<!-- {/DDCConfigRedWire/PicturesPathName/PicturesInfo -->
	<xsl:variable name="pictureInfo">
		<xsl:call-template name="PicturePath">
			<xsl:with-param name="alertLevel">Info</xsl:with-param>
			<xsl:with-param name="configRedWire"><xsl:value-of select="$configRedWire"/></xsl:with-param>
		</xsl:call-template>	
	</xsl:variable>

	<xsl:call-template name="traitementInfo">
		<xsl:with-param name="nb" select="$nbAlert+$nbWarning"/>
		<xsl:with-param name="imgPath"> <xsl:value-of select="$pictureInfo"/> </xsl:with-param>
	</xsl:call-template> 

	<xsl:variable name="nbInfo"> <xsl:value-of select="count(Message[AlertLevel[.='3']])"/> </xsl:variable>

	<!-- Specific End -->
	<xsl:call-template name="traitementComplement">
		<xsl:with-param name="nb" select="$nbAlert+$nbWarning+$nbInfo"/>
	</xsl:call-template> 
</xsl:template>

<xsl:template name="traitementComplement">
	<xsl:param name="nb"/>
	<xsl:choose>
		<xsl:when test="$nb='0'">
			pausecontent[0]=''
			pausecontent[1]=''
		</xsl:when>
		<xsl:when test="$nb='1'">
			pausecontent[1]=''
		</xsl:when>
	</xsl:choose>
</xsl:template>


<xsl:template name="traitementAlert">
	<xsl:param name="nb"/> 
	<xsl:param name="imgPath"/>

	<xsl:for-each select="Message[AlertLevel[.='1']]">
		pausecontent[<xsl:value-of select="$nb+position()-1"/>]='<img src="{$imgPath}"/>  <a class="AlertMsgProperties" href="{Location}" TARGET="_new"><xsl:value-of select="Title"/></a>'
	</xsl:for-each>
</xsl:template>

<xsl:template name="traitementWarning">
	<xsl:param name="nb"/> 
	<xsl:param name="imgPath"/>

	<xsl:for-each select="Message[AlertLevel[.='2']]">
		pausecontent[<xsl:value-of select="$nb+position()-1"/>]='<img src="{$imgPath}"/>  <a class="WarningMsgProperties" href="{Location}" TARGET="_new"><xsl:value-of select="Title"/></a>'
	</xsl:for-each>
</xsl:template>

<xsl:template name="traitementInfo">
	<xsl:param name="nb"/>
	<xsl:param name="imgPath"/>

	<xsl:for-each select="Message[AlertLevel[.='3']]">
		pausecontent[<xsl:value-of select="$nb+position()-1"/>]='<img src="{$imgPath}"/>  <a class="InformationMsgProperties" href="{Location}" TARGET="_new"><xsl:value-of select="Title"/></a>'
	</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
