﻿<?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="limit" select="100"/>
	<xsl:param name="titleLimit" select="30"/>
	<xsl:strip-space elements="true"/>
	<xsl:output omit-xml-declaration="yes" />

	<xsl:template match='//rs:data'>
		<div style='display: none;'>
			<table border="0" cellpadding="0" cellspacing="0" style="border: none; margin: 0px;
                    padding: 0px; width: 387px; font-family: Verdana, Sans-Serif; font-size: 11px;">
				<tbody>
					<xsl:apply-templates select='z:row'>
						<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 kandidaat-nieuwsberichten aanwezig in deze categorie.</div>
					</xsl:if>
				</tbody>
			</table>
		</div>
	</xsl:template>

	<xsl:template match='z:row'>
		<xsl:if test="@ows_Nieuwsbriefopname = 'Kandidaat'">
			<TR>
				<TD style="BORDER: white 1.5pt solid; PADDING: 0cm; BACKGROUND: white;">
					<table border="0" cellpadding="0" cellspacing="0" style="border: none; margin: 0px;
                                padding: 0px; width: 387px; line-height: 16px; font-family: Verdana, Sans-Serif;
                                font-size: 11px; background-color: #C6E1E8;">
						<TBODY>

							<tr>
								<td style="padding: 10px">
									<span>
										<xsl:variable name="rawUrl">
											<xsl:value-of select='substring-before(@ows_EncodedAbsUrl, "_.")'/>
										</xsl:variable>
										<xsl:variable name="link">
											<xsl:value-of select='concat(substring($rawUrl, 1, string-length($rawUrl) - string-length(string(@ows_ID))), "DispFormWindexCC.aspx?ID=", @ows_ID, "&amp;Source=/Leden")'/>
										</xsl:variable>

										<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: transparent;">
											<tr>
												<td>
													<span style="text-align:left; width:100%; font-weight: bold; line-height: 15px; ">
														<a title="Klik voor het volledige bericht" target="_blank" style="font-size: 15px; font-weight: bold; color: #147192; text-decoration: none;">
															<xsl:attribute name="href">
																<xsl:value-of select='$link'/>
															</xsl:attribute>
															<xsl:value-of select="@ows_LinkTitle" disable-output-escaping='yes'/>
														</a>
													</span>
												</td>
												<td align="right">
													<select id="NewsWebPartOrderingSelector">
													</select>

													<select id="NewsWebPartCandidateSelector">
														<option value="Kandidaat">Kandidaat</option>
														<option value="Geplaatst" selected="selected">Plaatsen</option>
														<option value="Niet geplaatst">Niet plaatsen</option>
													</select>
												</td>
											</tr>
										</table>
										<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>

										<span target="_blank" style="color: black; font-style: italic; line-height: 20px;">
											<xsl:attribute name="href">
												<xsl:value-of select='$link'/>
											</xsl:attribute>
											<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>
										<!-- end actions -->
										<br />
										<span name="NewsWebPartNewsBody" style="height: 70px;">
											<a title="Klik voor het volledige bericht" target="_blank" style="color: black; text-decoration: none;">
												<xsl:attribute name="href">
													<xsl:value-of select='$link'/>
												</xsl:attribute>
												<xsl:choose>
													<xsl:when test="string-length(@ows_Inleiding_x0020_nieuwsbrief) &lt; 1">
														<xsl:call-template name="removeHtmlTags">
															<xsl:with-param name="html" select="@ows_Body" />
														</xsl:call-template>
													</xsl:when>
													<xsl:otherwise>
														<xsl:choose>
															<xsl:when test="contains(@ows_Inleiding_x0020_nieuwsbrief, '&lt;')">
																<xsl:call-template name="removeHtmlTags">
																	<xsl:with-param name="html" select="@ows_Inleiding_x0020_nieuwsbrief" />
																</xsl:call-template>
															</xsl:when>
															<xsl:otherwise>
																<xsl:value-of select="@ows_Inleiding_x0020_nieuwsbrief" disable-output-escaping='yes'  />
															</xsl:otherwise>
														</xsl:choose>
													</xsl:otherwise>
												</xsl:choose>
											</a>
										</span>
										<span name="NewsWebPartCategoryLabel" style="display: none; color: #C6E1E8;">
											<xsl:value-of select="concat(@ows_Nieuwsbriefcategorie, ';#')" disable-output-escaping='yes'  />
										</span>
									</span>
								</td>
							</tr>
							<!--<tr>
								<td style="font-size: 4px; line-height: 10px;">
									 
								</td>
								<td style="font-size: 4px; line-height: 10px;">
									 
								</td>
								<td style="font-size: 4px; line-height: 10px;">
									 
								</td>
							</tr>-->
						</TBODY>
					</table>
				</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:template name="removeHtmlTags">
		<xsl:param name="html"/>
		<xsl:if test="contains($html, '&lt;')">
			<xsl:choose>
				<xsl:when test="substring(substring-after($html, '&lt;'), 1, 2) = 'a '">
					<xsl:value-of select="concat(substring-before($html, '&lt;/a&gt;'), '&lt;/a&gt;')" disable-output-escaping='yes'/>
					<!-- Recurse through HTML -->
					<xsl:call-template name="removeHtmlTags">
						<xsl:with-param name="html" select="substring-after($html, '&lt;/a&gt;')"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="substring(substring-after($html, '&lt;'), 1, 2) = 'br'">
					<br />
					<!-- Recurse through HTML -->
					<xsl:call-template name="removeHtmlTags">
						<xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="substring(substring-after($html, '&lt;'), 1, 2) = 'ul'">
					<xsl:value-of select="concat(substring-before($html, '&lt;/ul&gt;'), '&lt;/ul&gt;')" disable-output-escaping='yes'/>
					<!-- Recurse through HTML -->
					<xsl:call-template name="removeHtmlTags">
						<xsl:with-param name="html" select="substring-after($html, '&lt;/ul&gt;')"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="substring(substring-after($html, '&lt;'), 1, 2) = 'li'">
					<xsl:value-of select="concat(substring-before($html, '&lt;/li&gt;'), '&lt;/li&gt;')" disable-output-escaping='yes'/>
					<!-- Recurse through HTML -->
					<xsl:call-template name="removeHtmlTags">
						<xsl:with-param name="html" select="substring-after($html, '&lt;/li&gt;')"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
					<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:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>
