<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" version="1.0">
	<xsl:output method="xml" indent="yes" encoding="utf-8"/>
	<xsl:decimal-format name="european" decimal-separator="." grouping-separator=","/>
	<xsl:param name="mode"/>
	<xsl:variable name="Rev">
		<!-- Revision van deze cust.xsl -->
		<xsl:value-of select="substring(translate('$Revision$', '$ ', ''), 10)"/>
	</xsl:variable>

	<xsl:template match="rapport">
		<!-- ******************************************************************* -->
		<!-- *****TIBCO-request (of direct Smart Signs): GetReserveringen        -->
		<!-- ******************************************************************* -->
		<xsl:if test="@view='res_v_api_reserveringen'">
			<xsl:variable name="sorted">
				<xsl:for-each select="GetReserveringenResponse/reservering">
					<xsl:sort select="VAN"/>
					<xsl:sort select="LOCATIECODE"/>
					<xsl:sort select="GEBOUWCODE"/>
					<xsl:sort select="VERDIEPINGCODE"/>
					<xsl:sort select="RUIMTECODE"/>
					<xsl:sort select="KEY"/>
					<xsl:if test="RUIMTENAAM!=''">
					  <xsl:copy-of select="."/>
					</xsl:if>
				</xsl:for-each>
			</xsl:variable>

			<xsl:choose>
				<xsl:when test="$mode='Reserveringen'">
					<fclt:GetReserveringenResponse xmlns:fclt="http://facilitor.nl/reserveringen">
						<!--GetReserveringenResult>
						 <facilitor>
							<xsl:element name="reserveringen">
							<xsl:attribute name="type">response</xsl:attribute-->
						<xsl:for-each select="msxml:node-set($sorted)/reservering">
							<xsl:element name="fclt:reservering">
							<xsl:attribute name="key"><xsl:value-of select="KEY"/></xsl:attribute>
								<fclt:locatiecode><xsl:value-of select="LOCATIECODE"/></fclt:locatiecode>
								<fclt:gebouwcode><xsl:value-of select="GEBOUWCODE"/></fclt:gebouwcode>
								<fclt:verdiepingcode><xsl:value-of select="VERDIEPINGCODE"/></fclt:verdiepingcode>
								<fclt:ruimtecode><xsl:value-of select="RUIMTECODE"/></fclt:ruimtecode>
								<fclt:ruimtenaam><xsl:value-of select="RUIMTENAAM"/></fclt:ruimtenaam>
								<fclt:resid><xsl:value-of select="RESID"/></fclt:resid>
								<fclt:van><xsl:value-of select="VAN"/></fclt:van>
								<fclt:tot><xsl:value-of select="TOT"/></fclt:tot>
								<!--xsl:choose>
									<xsl:when test="fo_status_key='1'"><fo_status>RESOPT</fo_status></xsl:when>
									<xsl:when test="fo_status_key='2'"><fo_status>RESDEF</fo_status></xsl:when>
									<xsl:when test="fo_status_key='3'"><fo_status>RESBLK</fo_status></xsl:when>
									<xsl:when test="fo_status_key='4'"><fo_status>RESDEL</fo_status></xsl:when>
									<xsl:otherwise></xsl:otherwise>
								</xsl:choose-->
								<fclt:fo_status><xsl:value-of select="FO_STATUS"/></fclt:fo_status>
								<fclt:omschrijving><xsl:value-of select="OMSCHRIJVING"/></fclt:omschrijving>
								<fclt:contact><xsl:value-of select="CONTACT"/></fclt:contact>
								<fclt:host><xsl:value-of select="HOST"/></fclt:host>
							</xsl:element>
						</xsl:for-each>
							<!--/xsl:element>
						 </facilitor>
						</GetReserveringenResult-->
					</fclt:GetReserveringenResponse>
				</xsl:when>
				<xsl:otherwise>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>

	<!-- SOAP envelope met de afgesproken 'payload' in response op request! -->
	<!--xsl:template match="facilitor">
		<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
			<soap:Body>
				<xsl:apply-templates select="rapport"/>
			</soap:Body>
		</soap:Envelope>
	</xsl:template-->
	<xsl:template match="facilitor">
		<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
			<SOAP-ENV:Body>
				<xsl:apply-templates select="rapport"/>
			</SOAP-ENV:Body>
		</SOAP-ENV:Envelope>
	</xsl:template>

	<!-- De afgesproken 'payload' in response op request (zonder envelope)! -->
	<!--xsl:template match="facilitor">
		<xsl:apply-templates select="rapport"/>
	</xsl:template-->

	<!-- Root -->
	<xsl:template match="/">
		<xsl:apply-templates select="facilitor"/>
	</xsl:template>
</xsl:stylesheet>
