<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt">
	<xsl:output method="xml" indent="yes" encoding="utf-8"/>
	<xsl:decimal-format name="european" decimal-separator="," grouping-separator="."/>

	<xsl:param name="mode"/>
	<xsl:param name="srtnotificatiecode"/>

	<xsl:variable name="Rev">
		<!-- Revision van deze system2system.xsl -->
		<xsl:value-of select="substring(translate('$Revision$', '$ ', ''), 10)"/>
	</xsl:variable>

	<xsl:template match="melding">
		<facilitor>
			<xsl:element name="opdracht">
				<xsl:attribute name="key"><xsl:value-of select="externnr"/></xsl:attribute>
				<xsl:attribute name="type">update</xsl:attribute>
				<xsl:choose>
					<xsl:when test="$srtnotificatiecode='MLDNEW'">
						<mut_datum>
							<xsl:value-of select="tracking/track[@code='MLDNEW']/datum/jaar"/>-<xsl:value-of select="tracking/track[@code='MLDNEW']/datum/maand"/>-<xsl:value-of select="tracking/track[@code='MLDNEW']/datum/dag"/><xsl:text> </xsl:text><xsl:value-of select="tracking/track[@code='MLDNEW']/datum/tijd"/>:00
						</mut_datum>
						<xsl:if test="opmerking!=''"><opmerking><xsl:value-of select="opmerking"/></opmerking></xsl:if>
						<datumgereed>
							<xsl:value-of select="datum_gepland/jaar"/>-<xsl:value-of select="datum_gepland/maand"/>-<xsl:value-of select="datum_gepland/dag"/><xsl:text> </xsl:text><xsl:value-of select="datum_gepland/tijd"/>:00
						</datumgereed>
						<xsl:element name="kenmerk">
							<xsl:attribute name="naam">Ref. Nr. Leverancier</xsl:attribute>
							<xsl:value-of select="key"/>
						</xsl:element>
					</xsl:when>
					<xsl:when test="$srtnotificatiecode='MLDACP'">
						<mut_datum>
							<xsl:value-of select="tracking/track[@code='MLDACP']/datum/jaar"/>-<xsl:value-of select="tracking/track[@code='MLDACP']/datum/maand"/>-<xsl:value-of select="tracking/track[@code='MLDACP']/datum/dag"/><xsl:text> </xsl:text><xsl:value-of select="tracking/track[@code='MLDACP']/datum/tijd"/>:00
						</mut_datum>
						<status>ORDACP</status>
						<xsl:if test="opmerking!=''"><opmerking><xsl:value-of select="opmerking"/></opmerking></xsl:if>
						<datumgereed>
							<xsl:value-of select="datum_gepland/jaar"/>-<xsl:value-of select="datum_gepland/maand"/>-<xsl:value-of select="datum_gepland/dag"/><xsl:text> </xsl:text><xsl:value-of select="datum_gepland/tijd"/>:00
						</datumgereed>
						<xsl:element name="kenmerk">
							<xsl:attribute name="naam">Ref. Nr. Leverancier</xsl:attribute>
							<xsl:value-of select="key"/>
						</xsl:element>
					</xsl:when>
					<xsl:when test="$srtnotificatiecode='MLDAFM'">
						<mut_datum>
							<xsl:value-of select="tracking/track[@code='MLDAFM']/datum/jaar"/>-<xsl:value-of select="tracking/track[@code='MLDAFM']/datum/maand"/>-<xsl:value-of select="tracking/track[@code='MLDAFM']/datum/dag"/><xsl:text> </xsl:text><xsl:value-of select="tracking/track[@code='MLDAFM']/datum/tijd"/>:00
						</mut_datum>
						<status>ORDAFM</status>
						<xsl:if test="opmerking!=''"><opmerking><xsl:value-of select="opmerking"/></opmerking></xsl:if>
						<datumgereed>
							<xsl:value-of select="datum_gepland/jaar"/>-<xsl:value-of select="datum_gepland/maand"/>-<xsl:value-of select="datum_gepland/dag"/><xsl:text> </xsl:text><xsl:value-of select="datum_gepland/tijd"/>:00
						</datumgereed>
					</xsl:when>
					<xsl:when test="$srtnotificatiecode='MLDAFR'">
						<mut_datum>
							<xsl:value-of select="tracking/track[@code='MLDAFR']/datum/jaar"/>-<xsl:value-of select="tracking/track[@code='MLDAFR']/datum/maand"/>-<xsl:value-of select="tracking/track[@code='MLDAFR']/datum/dag"/><xsl:text> </xsl:text><xsl:value-of select="tracking/track[@code='MLDAFR']/datum/tijd"/>:00
						</mut_datum>
						<status>ORDAFR</status>
						<kosten><xsl:value-of select="kenmerk[@naam='Kosten']"/></kosten>
					</xsl:when>
					<xsl:when test="$srtnotificatiecode='MLDREJ' or status_key='1'">
						<mut_datum>
							<xsl:value-of select="tracking/track[@code='MLDREJ']/datum/jaar"/>-<xsl:value-of select="tracking/track[@code='MLDREJ']/datum/maand"/>-<xsl:value-of select="tracking/track[@code='MLDREJ']/datum/dag"/><xsl:text> </xsl:text><xsl:value-of select="tracking/track[@code='MLDREJ']/datum/tijd"/>:00
						</mut_datum>
						<!--status>ORDAFM</status-->
						<status>ORDCAN</status>
						<opmerking>Afgewezen. <xsl:if test="opmerking!=''"><xsl:value-of select="opmerking"/></xsl:if></opmerking>
						<datumgereed>
							<xsl:value-of select="datum_gepland/jaar"/>-<xsl:value-of select="datum_gepland/maand"/>-<xsl:value-of select="datum_gepland/dag"/><xsl:text> </xsl:text><xsl:value-of select="datum_gepland/tijd"/>:00
						</datumgereed>
						<kosten><xsl:value-of select="format-number(sum(opdracht/kosten), '0,00', 'european')"/></kosten>
					</xsl:when>
					<xsl:otherwise>
						<xsl:variable name="maxtrack">
							<xsl:for-each select="tracking/track/datum">
								<xsl:sort select="timestamp" data-type="number" order="descending"/>
								<xsl:if test="position()=1"><xsl:copy-of select="."/></xsl:if>
							</xsl:for-each>
						</xsl:variable>
						<mut_datum>
							<xsl:value-of select="msxml:node-set($maxtrack)/datum/jaar"/>-<xsl:value-of select="msxml:node-set($maxtrack)/datum/maand"/>-<xsl:value-of select="msxml:node-set($maxtrack)/datum/dag"/><xsl:text> </xsl:text><xsl:value-of select="msxml:node-set($maxtrack)/datum/tijd"/>:00
						</mut_datum>
						<xsl:if test="opmerking!=''"><opmerking><xsl:value-of select="opmerking"/></opmerking></xsl:if>
						<datumgereed>
							<xsl:value-of select="datum_gepland/jaar"/>-<xsl:value-of select="datum_gepland/maand"/>-<xsl:value-of select="datum_gepland/dag"/><xsl:text> </xsl:text><xsl:value-of select="datum_gepland/tijd"/>:00
						</datumgereed>
					</xsl:otherwise>
				</xsl:choose>
				<!--xsl:element name="kenmerk">
					<xsl:attribute name="naam">???</xsl:attribute>
					<xsl:element name="FCLTmeldingattachment">
						<xsl:attribute name="meldingkey"><xsl:value-of select="key"/></xsl:attribute>
						<xsl:attribute name="kenmerkkey">???</xsl:attribute>
						<xsl:attribute name="nodename">???</xsl:attribute>
					</xsl:element>
				</xsl:element-->
			</xsl:element>
		</facilitor>
	</xsl:template>

	<xsl:template match="facilitor">
		<xsl:apply-templates select="melding"/>
	</xsl:template>

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