<?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:param name="mode"/>

<xsl:template match="bestelopdracht">
<xsl:comment>Facilitor custom XSL template for cXML bestelopdracht</xsl:comment>
<xsl:element name="cXML">
  <xsl:attribute name="payloadID"><xsl:value-of select="datum/timestamp"/>@http://mycomp.com</xsl:attribute>
  <xsl:attribute name="timestamp"><xsl:value-of select="/facilitor/header/dateYear"/>-<xsl:value-of select="/facilitor/header/dateMonth"/>-<xsl:value-of select="/facilitor/header/dateDay"/>T<xsl:value-of select="substring(/facilitor/header/dateTime,12,8)"/>+01:00</xsl:attribute>
  <xsl:attribute name="xml:lang">NL</xsl:attribute>
	<Header>
		<From>
			<Credential domain="Facilitor" type="marketplace">
				<Identity>order@facilityplace.nl</Identity>
			</Credential>
		</From>
		<To>
		    <xsl:element name="Credential">
		     <xsl:attribute name="domain"><xsl:value-of select="bedrijf/naam"/></xsl:attribute>
				<Identity><xsl:value-of select="bedrijf/leverancier_nr"/></Identity>
			</xsl:element>
		</To>
		<Sender>
			<Credential domain="Facilitor">
				<Identity>order@facilityplace.nl</Identity>
			</Credential>
			<UserAgent></UserAgent>
		</Sender>
	</Header>
	<Request deploymentMode="test">
		<OrderRequest>
		    <xsl:element name="OrderRequestHeader">
			<xsl:attribute name="orderID"><xsl:value-of select="id"/></xsl:attribute>
			<xsl:attribute name="orderDate"><xsl:value-of select="/facilitor/bestelopdracht/datum/jaar"/>-<xsl:value-of select="/facilitor/bestelopdracht/datum/maand"/>-<xsl:value-of select="/facilitor/bestelopdracht/datum/dag"/></xsl:attribute>
			<xsl:attribute name="type">new</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:attribute name="addressID"><xsl:value-of select='bedrijf/overeenkomst_nr'/></xsl:attribute>
						<Name xml:lang="NL">(<xsl:value-of select="afleveradres/naam"/>)</Name>
					<PostalAddress name="default">
						<DeliverTo><xsl:value-of select="bestelling/voor/voornaam"/>, <xsl:if test="bestelling/voor/tussenvoegsel!=''"><xsl:value-of select="bestelling/voor/tussenvoegsel"/>&#160;</xsl:if><xsl:value-of select="bestelling/voor/naam"/></DeliverTo>
						<DeliverTo><xsl:value-of select="bestelling/plaats"/></DeliverTo>
						<Street><xsl:value-of select="afleveradres/bezoek_adres"/></Street>
						<City><xsl:value-of select="afleveradres/bezoek_plaats"/></City>
						<State></State>
						<PostalCode><xsl:value-of select="afleveradres/bezoek_postcode"/></PostalCode>
						<Country isoCountryCode="NL">Netherlands</Country>
					</PostalAddress>
				</xsl:element>
			</ShipTo>
			<BillTo>
      			   <xsl:element name="Address">
				   <xsl:attribute name="addressID"></xsl:attribute>
					<Name xml:lang="NL"></Name>
					  <Contactpersoon><xsl:value-of select="factuuradres/contactpersoon"/></Contactpersoon>
						<Contactpers_telefoon><xsl:value-of select="factuuradres/contactpers_telefoon"/></Contactpers_telefoon>
					<PostalAddress name="default">
						<Street><xsl:value-of select="factuuradres/post_adres"/></Street>
						<City><xsl:value-of select="factuuradres/post_plaats"/></City>
						<State></State>
						<PostalCode><xsl:value-of select="factuuradres/post_postcode"/></PostalCode>
						<Country isoCountryCode="NL">Netherlands</Country>
					</PostalAddress>
				</xsl:element>
			</BillTo>
			<Contact>
					<Name xml:lang="NL">
						<xsl:value-of select="bestelling/voor/voornaam"/>, <xsl:if test="bestelling/voor/tussenvoegsel!=''"><xsl:value-of select="bestelling/voor/tussenvoegsel"/>&#160;</xsl:if><xsl:value-of select="bestelling/voor/naam"/>
					</Name>
					<Email>
						<xsl:value-of select="bestelling/voor/email"/>
					</Email>
					<Phone>
						<TelephoneNumber>
							<CountryCode isoCountryCode="NL"/>
							<AreaOrCityCode/>
							<Number>
								<xsl:value-of select="bestelling/voor/telefoonnr"/>
							</Number>
						</TelephoneNumber>
					</Phone>
			</Contact>

			<Payment>
				<PCard number="1234567890123456" expiration="1999-03-12"/>
			</Payment>
			<Comments xml:lang="NL"><!-- <table cellspacing="1" class="cm"><tr><th class="cm" colspan=2>Ahrend Office Products B.V.</th></tr><tr><td class="cmh">Address:</td><td class="cm">Postbus 2400,3430 EA,NIEUWEGEIN</td></tr><tr><td class="cmh">Phone:</td><td class="cm">030-6020200</td></tr><tr><td class="cmh">Fax:</td><td class="cm">030-6020411</td></tr><tr><td class="cmh">email:</td><td class="cm"><a href="mailto: "> </a></td></tr></table>-->
			<xsl:for-each select="kenmerk">
              <br/><xsl:value-of select="@naam"/>:&#160;<xsl:value-of select="."/>
            </xsl:for-each>
			</Comments>
			<Extrinsic name="Costcenter"><xsl:value-of select='bestelling/kostenplaats/nr'/></Extrinsic>
				<xsl:for-each select="bestelling/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>
		</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/jaar'/>-<xsl:value-of select='/facilitor/bestelopdracht/bestelling/leverdatum/maand'/>-<xsl:value-of select='/facilitor/bestelopdracht/bestelling/leverdatum/dag'/></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="SPSC">12345</Classification>
				<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>
			<Comments xml:lang="NL">
			<xsl:for-each select="bestelitem/kenmerk">
              <br/><xsl:value-of select="@naam"/>:&#160;<xsl:value-of select="."/>
            </xsl:for-each>
			</Comments>
		</xsl:element>
       </xsl:for-each>
		</OrderRequest>
	</Request>
</xsl:element>
</xsl:template>

<xsl:template match="facilitor">
 <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:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2007. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="yes" url="..\..\..\TEMP\SORO_files\bestelopdr1163_20160112172825.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>
-->