<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" encoding="UTF-8"/>

	<xsl:decimal-format name="european" decimal-separator="." grouping-separator=","/>
	<xsl:variable name="Rev">
		<xsl:value-of select="substring(translate('$Revision$', '$ ', ''), 10)"/>
	</xsl:variable>

	<xsl:param name="mode"/>

	<xsl:template match="bestelling" mode="DeliverTo_BestemdVoor">
			<xsl:choose>
				<xsl:when test="./kenmerk[@naam='Afgeven bij']">
					<xsl:value-of select="./kenmerk[@naam='Bestemd voor']"/>(Afgeven bij: <xsl:value-of select="./kenmerk[@naam='Afgeven bij']"/>)
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="./kenmerk[@naam='Bestemd voor']"/>
				</xsl:otherwise>
			</xsl:choose>
			
	</xsl:template>

	<xsl:template match="bestelopdracht">
		<xsl:comment>Facilitor custom XSL template for cXML bestelopdracht</xsl:comment>
		<xsl:element name="cXML">
			<xsl:attribute name="version">1.2.016</xsl:attribute>
			<xsl:attribute name="payloadID">O-<xsl:value-of select="id"/></xsl:attribute>
			<xsl:attribute name="timestamp"><xsl:value-of select="datum/jaar"/>-<xsl:value-of select="datum/maand"/>-<xsl:value-of select="datum/dag"/>T<xsl:value-of select="datum/tijd"/>:00+01:00</xsl:attribute>
			<xsl:attribute name="xml:lang">NL</xsl:attribute>
			<Header>
		    <From>
			    <Credential domain="Facilitor" type="marketplace">
				    <Identity>UWV2891525</Identity>
			    </Credential>
		    </From>
				<To>
					<xsl:element name="Credential">
						<xsl:attribute name="domain"><xsl:value-of select="bedrijf/naam"/></xsl:attribute>
						<Identity/>
					</xsl:element>
				</To>
				<Sender>
					<Credential domain="Facilitor">
						<Identity/>
					</Credential>
					<UserAgent/>
				</Sender>
			</Header>
			<Request>
				<OrderRequest>
					<xsl:element name="OrderRequestHeader">
						<xsl:attribute name="orderID">O-<xsl:value-of select="id"/></xsl:attribute>
						<xsl:attribute name="orderDate"><xsl:value-of select="datum/datum"/></xsl:attribute>
						<Total>
							<Money currency="EUR">
								<xsl:value-of select="format-number(sum(bestelopdrachtitem/totaal), '0.00', 'european')"/>
							</Money>
						</Total>
						<ShipTo>
							<xsl:element name="Address">
								<xsl:choose>
									<xsl:when test="bestelling/kenmerk[@naam='Plaats']">
										<xsl:attribute name="addressID"/>
										<Name xml:lang="NL">
											<xsl:value-of select="bestelling/kenmerk[@naam='Bestemd voor']"/>
										</Name>
										<PostalAddress name="default">
											<DeliverTo>
												<xsl:apply-templates select="bestelling" mode="DeliverTo_BestemdVoor"/>
											</DeliverTo>
											<Street>
												<xsl:value-of select="bestelling/kenmerk[@naam='Straat huisnummer']"/>
											</Street>
											<City>
												<xsl:value-of select="bestelling/kenmerk[@naam='Plaats']"/>
											</City>
											<State/>
											<PostalCode>
												<xsl:value-of select="bestelling/kenmerk[@naam='Postcode']"/>
											</PostalCode>
											<Country isoCountryCode="NL"/>
										</PostalAddress>
									</xsl:when>
									<xsl:otherwise>
										<!--Als addressID is gebouwcode gewenst (door xxx locatiecode genoemd)!-->
										<xsl:variable name="varNaam">
											<xsl:value-of select="afleveradres/naam"/>
										</xsl:variable>
										<xsl:attribute name="addressID"><xsl:value-of select="substring($varNaam,1,5)"/></xsl:attribute>
										<Name xml:lang="NL">UWV (<xsl:value-of select="afleveradres/naam"/>)</Name>
										<PostalAddress>
											<DeliverTo>
    								    		<xsl:value-of select="bestelling/aanvrager/naam_full"/>
											</DeliverTo>
   								    		<xsl:if test="bestelling/plaats != ''">
   								    		    <DeliverTo>
   								    		        <xsl:value-of select="bestelling/plaats"/>
   								    		    </DeliverTo>
   								    		</xsl:if>
											<Street>
												<xsl:value-of select="afleveradres/bezoek_adres"/>
											</Street>
											<City>
												<xsl:value-of select="afleveradres/bezoek_plaats"/>
											</City>
											<State/>
											<PostalCode>
												<xsl:value-of select="afleveradres/bezoek_postcode"/>
											</PostalCode>
											<Country isoCountryCode="NL"/>
										</PostalAddress>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:element>
						</ShipTo>
						<BillTo>
							<xsl:element name="Address">
								<xsl:attribute name="addressID">AMSG3</xsl:attribute>
								<Name xml:lang="NL">
									<xsl:value-of select="factuuradres/naam"/>
								</Name>
								<PostalAddress>
									<Street>
										<xsl:value-of select="factuuradres/post_adres"/>
									</Street>
									<City>
										<xsl:value-of select="factuuradres/post_plaats"/>
									</City>
									<State/>
									<PostalCode>
										<xsl:value-of select="factuuradres/post_postcode"/>
									</PostalCode>
									<Country isoCountryCode="NL"/>
								</PostalAddress>
							</xsl:element>
						</BillTo>
						<Contact>
							<Name xml:lang="NL">
								<xsl:value-of select="bestelling/aanvrager/naam_full"/>
							</Name>
							<Email>
								<xsl:value-of select="bestelling/aanvrager/email"/>
							</Email>
							<Phone>
								<TelephoneNumber>
									<CountryCode isoCountryCode="NL"/>
									<AreaOrCityCode/>
									<Number>
										<xsl:value-of select="bestelling/aanvrager/telefoonnr"/>
									</Number>
								</TelephoneNumber>
							</Phone>
						</Contact>
						<Extrinsic name="BezorgInfo">
							<xsl:value-of select="bestelling/kenmerk[@naam='Bezorg info']"/>
							<!--xsl:if test="bestelling/activiteit != ''">[Abonnement] </xsl:if><xsl:value-of select="bestelling/kenmerk[@naam='Bezorg info']"/-->
						</Extrinsic>
						<Extrinsic name="CostCenter">
							<xsl:value-of select="bestelling/kostenplaats/nr"/>
						</Extrinsic>
					</xsl:element>
					<xsl:for-each select="bestelopdrachtitem">
						<xsl:sort select="srtdeel/omschrijving"/>
						<xsl:sort select="posnr"/>
						<xsl:element name="ItemOut">
							<xsl:attribute name="quantity"><xsl:value-of select="aantal"/></xsl:attribute>
							<xsl:attribute name="lineNumber"><xsl:value-of select="posnr"/></xsl:attribute>
							<xsl:attribute name="requestedDeliveryDate"><xsl:value-of select="/facilitor/bestelopdracht/bestelling/leverdatum/datum"/></xsl:attribute>
							<ItemID>
								<SupplierPartID>
									<xsl:value-of select="bestelitem/srtdeel/artikel_nummer"/>
								</SupplierPartID>
							</ItemID>
							<ItemDetail>
								<UnitPrice>
									<Money currency="EUR">
										<xsl:value-of select="prijs"/>
									</Money>
								</UnitPrice>
								<Description xml:lang="NL">
									<xsl:value-of select="bestelitem/srtdeel/omschrijving"/>
								</Description>
								<UnitOfMeasure><xsl:value-of select='bestelitem/srtdeel/eenheid'/></UnitOfMeasure>
								<Classification domain=""/>
								<xsl:for-each select="bestelitem/kenmerk">
									<xsl:if test="@type!='Q' and @type!='L'">
										<xsl:element name="Extrinsic">
											<xsl:attribute name="name"><xsl:value-of select="@naam"/></xsl:attribute>
											<xsl:value-of select="."/>
										</xsl:element>
									</xsl:if>
								</xsl:for-each>
							</ItemDetail>
						</xsl:element>
					</xsl:for-each>
				</OrderRequest>
			</Request>
		</xsl:element>
	</xsl:template>




	<xsl:template match="stock_request">
		<!--Facilitor custom XSL template for stock_request info -->
		<xsl:element name="stock_request">
    		<xsl:element name="part">
        		<xsl:element name="number">
    				<xsl:value-of select="part/number"/>
        		</xsl:element>
		    </xsl:element>
		</xsl:element>
	</xsl:template>

    <xsl:template match="stock_response">
		<!--Facilitor custom XSL template for stock_response info -->
		<xsl:element name="facilitor">
    		<xsl:element name="stock_response">
        		<xsl:element name="part">
            		<xsl:element name="number">
        				<xsl:value-of select="part/number"/>
            		</xsl:element>
            		<xsl:element name="amount">
        				<xsl:value-of select="part/amount"/>
            		</xsl:element>
    		    </xsl:element>
    		</xsl:element>
		</xsl:element>
	</xsl:template>

	
	<xsl:template match="facilitor">
		<xsl:apply-templates select="folder"/>
		<xsl:apply-templates select="stock_request"/>
		<xsl:apply-templates select="bestelopdracht"/>
	</xsl:template>

	<xsl:template match="/">
		<xsl:choose>
			<xsl:when test="$mode='getExtension'">
				<xsl:element name="format">
					<xsl:element name="extension">xml</xsl:element>
				</xsl:element>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="facilitor"/>
				<xsl:apply-templates select="stock_response"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="..\..\..\reportsCache\UWVAbestelopdr9986.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->