﻿<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:rs='urn:schemas-microsoft-com:rowset'
 	 xmlns:z='#RowsetSchema'
	xmlns:date="http://www.ora.com/XSLTCookbook/NS/dates"
   xml:space="default"
	version="1.0">

	<xsl:param name="category"></xsl:param>
	<xsl:param name="title"></xsl:param>
	<xsl:param name="path"></xsl:param>
	<xsl:param name="url"></xsl:param>
	<xsl:param name="items"></xsl:param>
	<xsl:param name="height"></xsl:param>
	<xsl:param name="citates"></xsl:param>
	<xsl:param name="limit" select="100"/>
	<xsl:param name="titleLimit" select="30"/>
	<xsl:strip-space elements="true"/>
	<xsl:output omit-xml-declaration="yes" />
	<xsl:variable name="quot">"</xsl:variable>

	<xsl:template match='//rs:data'>
		<style type="text/css">
			<xsl:text>

		.wccCitaatVerborgen
		{
			display: none;
		}
		</xsl:text>
		</style>
		<h3 class="ms-standardheader ms-WPTitle'">
			<xsl:value-of select='@ows_LinkTitle' disable-output-escaping='yes'  />
		</h3>
		<table border='0' cellpadding='0' cellspacing='0' width='100%'>
			<tbody>
				<tr>
					<td name="CurrentItemImageCell" class="CurrentItemImageCell">
						<div style="width: 680px; position: absolute;">
							<div id="NewsItemCitate">
								<xsl:attribute name="class">
									<xsl:value-of select='concat("wccCitaat", z:row[1]/@ows_Citaatpositie)'/>
								</xsl:attribute>
								<xsl:attribute name="style">
									<xsl:value-of select="concat('position: relative; display: ', ';')"/>
								</xsl:attribute>
								<xsl:value-of select='concat("&#8220;", translate(z:row[1]/@ows_Citaat, $quot, ""), "&#8221;")'/>
							</div>
						</div>
						<img id="CurrentItemImage" class="CurrentItemImage">
							<xsl:attribute name="src">
								<xsl:choose>
									<xsl:when test="$items = 2">
										<xsl:value-of select='substring-before(z:row[1]/@ows_Afbeelding2, ",")'/>
									</xsl:when>
									<xsl:when test="$items = 3">
										<xsl:value-of select='substring-before(z:row[1]/@ows_Afbeelding3, ",")'/>
									</xsl:when>
									<xsl:when test="$items = 4">
										<xsl:value-of select='substring-before(z:row[1]/@ows_Afbeelding4, ",")'/>
									</xsl:when>
									<xsl:when test="$items = 5">
										<xsl:value-of select='substring-before(z:row[1]/@ows_Afbeelding5, ",")'/>
									</xsl:when>
								</xsl:choose>
							</xsl:attribute>
						</img>
					</td>
					<td>
						<table border='0' cellpadding='0' cellspacing='0' width='100%'>
							<tbody>
								<xsl:apply-templates select='z:row[position() &lt; $items + 1]'>
									<xsl:sort select="@ows_Datum" order="descending"/>
								</xsl:apply-templates>
								<xsl:variable name="rows" select="z:row" />
								<xsl:if test="count($rows) &lt; 1">
									<div style="padding:10px;">Er zijn geen nieuwsberichten aanwezig in deze categorie.</div>
								</xsl:if>
							</tbody>
						</table>
					</td>
				</tr>
			</tbody>
		</table>
		
	</xsl:template>

	<xsl:template match='z:row'>
		<!--<xsl:if test="contains(@ows_Tonen_x0020_in, concat(';#', $title, ';#'))">-->
			<tr>
				<xsl:choose>
					<xsl:when test="position() = 1">
						<xsl:attribute name="class">wccNewsTextHover</xsl:attribute>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="class">wccNewsText</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				<td class="wccNewsArrowCell">
					<img name="NewsItemArrow" src="_layouts/images/pijl.gif">
						<xsl:choose>
							<xsl:when test="position() = 1">
								<xsl:attribute name="class">wccNewsArrowActive</xsl:attribute>
							</xsl:when>
							<xsl:otherwise>
								<xsl:attribute name="class">wccNewsArrow</xsl:attribute>
							</xsl:otherwise>
						</xsl:choose>
					</img>
				</td>
				<td>
					<div class="wccNewsText">
						<xsl:variable name="rawUrl">
							<xsl:value-of select='substring-before(@ows_EncodedAbsUrl, "_.")'/>
						</xsl:variable>
						<xsl:attribute name="onclick">
							<xsl:choose>
								<xsl:when test="string-length(@ows_Alternatieve_x0020_Link) &gt; 0">
									<xsl:choose>
										<xsl:when test="@ows_Openen_x0020_in_x0020_nieuw_x002 = 1">
											<xsl:value-of select='concat("window.open(&apos;", substring-before(@ows_Alternatieve_x0020_Link, ","), "&apos;);")'/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select='concat("document.location=&apos;", substring-before(@ows_Alternatieve_x0020_Link, ","), "&apos;;")'/>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select='concat("document.location=&apos;", substring($rawUrl, 1, string-length($rawUrl) - string-length(string(@ows_ID))), "/DispFormWindexCC.aspx?ID=", @ows_ID, "&amp;Source=", $url, "&apos;;")'/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:attribute>
						<xsl:attribute name="onmouseout">DelayNewsItem();</xsl:attribute>
						<xsl:attribute name="onmouseover">
							<xsl:value-of select='concat("HoverNewsItem(this, ", position() - 1, ");")'/>
						</xsl:attribute>
						
						<img name="NewsItemImage" style="display: none;">
							<xsl:attribute name="src">
								<xsl:choose>
									<xsl:when test="$items = 2">
										<xsl:value-of select='substring-before(@ows_Afbeelding2, ",")'/>
									</xsl:when>
									<xsl:when test="$items = 3">
										<xsl:value-of select='substring-before(@ows_Afbeelding3, ",")'/>
									</xsl:when>
									<xsl:when test="$items = 4">
										<xsl:value-of select='substring-before(@ows_Afbeelding4, ",")'/>
									</xsl:when>
									<xsl:when test="$items = 5">
										<xsl:value-of select='substring-before(@ows_Afbeelding5, ",")'/>
									</xsl:when>
								</xsl:choose>
							</xsl:attribute>
							<xsl:attribute name="alt">
								<xsl:value-of select='concat("wccCitaat", @ows_Citaatpositie)'/>
							</xsl:attribute>
							<xsl:attribute name="title">
								<xsl:value-of select='concat("&#8220;", translate(@ows_Citaat, $quot, ""), "&#8221;")'/>
							</xsl:attribute>
						</img>
						<span id="Actions" style="width:100%;">
							<table width="100%" cellspacing="0" cellpadding="0">
								<tr>
									<td>
										<span style="text-align:left; width:100%;" class="wccNewsHeader">
											<xsl:choose>
												<xsl:when test="string-length(@ows_Titel_x0020_spotlight) &lt; 1">
													<xsl:choose>
														<xsl:when test="string-length(@ows_LinkTitle) &lt; 1">
															<xsl:value-of select="substring(@ows_Body,0,$titleLimit)" disable-output-escaping='yes'/>
														</xsl:when>
														<xsl:otherwise>
															<xsl:value-of select='@ows_LinkTitle' disable-output-escaping='yes'  />
														</xsl:otherwise>
													</xsl:choose>
												</xsl:when>
												<xsl:otherwise>
													<xsl:value-of select='@ows_Titel_x0020_spotlight' disable-output-escaping='yes'  />
												</xsl:otherwise>
											</xsl:choose>
										</span>
									</td>
								</tr>
							</table>
							<span>
								<a style="color: #999;">
									<xsl:attribute name="href">
										<xsl:value-of select='source/@url'/>
									</xsl:attribute>
									<xsl:value-of select='source'/>
								</a>
								<xsl:text disable-output-escaping="yes"> </xsl:text>

								<xsl:call-template name="date:calculate-day-of-the-week">
									<xsl:with-param name="year" select='substring(@ows_Datum,1,4)'/>
									<xsl:with-param name="month" select='substring(@ows_Datum,6,2)'/>
									<xsl:with-param name="day" select='substring(@ows_Datum,9,2)'/>
								</xsl:call-template>
								<xsl:value-of select='number(substring(@ows_Datum,9,2))'/>
								<xsl:variable name="mo">
									<xsl:value-of select='substring(@ows_Datum,6,2)'/>
								</xsl:variable>
								<xsl:choose>
									<xsl:when test="$mo = '01'"> januari </xsl:when>
									<xsl:when test="$mo = '02'"> februari </xsl:when>
									<xsl:when test="$mo = '03'"> maart </xsl:when>
									<xsl:when test="$mo = '04'"> april </xsl:when>
									<xsl:when test="$mo = '05'"> mei </xsl:when>
									<xsl:when test="$mo = '06'"> juni </xsl:when>
									<xsl:when test="$mo = '07'"> juli </xsl:when>
									<xsl:when test="$mo = '08'"> augustus </xsl:when>
									<xsl:when test="$mo = '09'"> september </xsl:when>
									<xsl:when test="$mo = '10'"> oktober </xsl:when>
									<xsl:when test="$mo = '11'"> november </xsl:when>
									<xsl:when test="$mo = '12'"> december </xsl:when>
								</xsl:choose>
								<xsl:value-of select='substring(@ows_Datum,1,4)'/>
							</span>
						</span>
						<!-- end actions -->

						<div name="NewsWebPartNewsBody" class="wccNewsBody">
							<xsl:attribute name="style">
								<xsl:value-of select="concat('height: ', $height, 'px')"/>
							</xsl:attribute>
							<xsl:choose>
								<xsl:when test="string-length(@ows_Ondertitel_x0020_spotlight) &lt; 1">
									<xsl:choose>
										<xsl:when test="string-length(@ows_Inleiding) &lt; 1">
											<xsl:value-of select="@ows_Body" disable-output-escaping='yes'/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="@ows_Inleiding" disable-output-escaping='yes'  />
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="@ows_Ondertitel_x0020_spotlight" disable-output-escaping='yes'  />
								</xsl:otherwise>
							</xsl:choose>
						</div>
						<!--<div name="NewsWebPartCategoryLabel" style="display: none;">
							<xsl:value-of select="substring-before(substring-after(description, 'Nieuwsbriefcategorie:&lt;/b&gt;'), '&lt;')" disable-output-escaping='yes'  />
						</div>-->
					</div>
				</td>
			</tr>
		<!--</xsl:if>-->
	</xsl:template>

	<xsl:template name="date:calculate-day-of-the-week">
		<xsl:param name="date-time"/>
		<xsl:param name="date" select="substring-before($date-time,'T')"/>
		<xsl:param name="year" select="substring-before($date,'-')"/>
		<xsl:param name="month"
			  select="substring-before(substring-after($date,'-'),'-')"/>
		<xsl:param name="day" select="substring-after(substring-after($date,'-'),'-')"/>

		<xsl:variable name="a" select="floor((14 - $month) div 12)"/>
		<xsl:variable name="y" select="$year - $a"/>
		<xsl:variable name="m" select="$month + 12 * $a - 2"/>

		<xsl:variable name="d" select="($day + $y + floor($y div 4) - floor($y div 100) 
    + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>
		<xsl:choose>
			<xsl:when test="$d = 1">maandag </xsl:when>
			<xsl:when test="$d = 2">dinsdag </xsl:when>
			<xsl:when test="$d = 3">woensdag </xsl:when>
			<xsl:when test="$d = 4">donderdag </xsl:when>
			<xsl:when test="$d = 5">vrijdag </xsl:when>
			<xsl:when test="$d = 6">zaterdag </xsl:when>
			<xsl:when test="$d = 0">zondag </xsl:when>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>
