﻿<?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'>
		<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>
				<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>
	</xsl:template>

	<xsl:template match='z:row'>
		<tr>
			<td>
				<div class="wccNewsHomeItem">
					<xsl:variable name="rawUrl">
						<xsl:value-of select='substring-before(@ows_EncodedAbsUrl, "_.")'/>
					</xsl:variable>
					<xsl:variable 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:variable>
					<xsl:variable name='plainIntro'>
						<xsl:call-template name="removeHtmlTags">
							<xsl:with-param name="html" select="@ows_Inleiding" />
						</xsl:call-template>
					</xsl:variable>
					<xsl:variable name='plainBody'>
						<xsl:call-template name="removeHtmlTags">
							<xsl:with-param name="html" select="@ows_Body" />
						</xsl:call-template>
					</xsl:variable>
					<div class="wccNewsHomeBody">
						<div class="wccNewsHomeBodyText">
							<table width="100%" cellspacing="0" cellpadding="0">
								<tr class="wccNewsHeaderRow">
									<td>
										<a>
											<xsl:if test="string-length($plainBody) &gt; 10 and $plainIntro != $plainBody">
												<xsl:attribute name="onclick">
													<xsl:value-of select="$onclick"/>
												</xsl:attribute>
											</xsl:if>
											<span class="wccNewsHeader">
												<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>
											</span>
										</a>
									</td>
								</tr>
								<tr>
									<td>
										<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_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>
										</div>
										<xsl:if test="string-length($plainBody) &gt; 10 and $plainIntro != $plainBody">
											<div align='right' class='wccNewsReadFurtherLink'>
												<a href="#">
													<xsl:attribute name="onclick">
														<xsl:value-of select="$onclick"/>
													</xsl:attribute>
													<span class='wccNewsReadFurther'>&#160;Lees verder&#160;</span>
												</a>
											</div>
										</xsl:if>
									</td>
								</tr>
							</table>
						</div>
						<div class="wccNewsHomeBodyImage">
							<img border="1" style="border: 1px solid #dddddd;">
								<xsl:attribute name="src">
									<xsl:value-of select="substring-before(@ows_AfbeeldingRechts, ',')"/>
								</xsl:attribute>
							</img>
						</div>							
					</div>
				</div>
			</td>
		</tr>
	</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:template name="removeHtmlTags">
		<xsl:param name="html"/>
		<xsl:choose>
			<xsl:when test="contains($html, '&lt;')">
				<xsl:value-of select="substring-before($html, '&lt;')"/>
				<!-- Recurse through HTML -->
				<xsl:call-template name="removeHtmlTags">
					<xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$html"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
