<?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">2006-05-10T12:41:47+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>8712423002180</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">Welkom (<xsl:value-of select="afleveradres/naam"/>)</Name>
					<PostalAddress name="default">
						<DeliverTo><xsl:value-of select="bestelling/aanvrager/naam_full"/></DeliverTo>
						<DeliverTo></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:value-of select='bedrijf/overeenkomst_nr'/></xsl:attribute>
					<Name xml:lang="NL">Welkom</Name>
					<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>
			<Payment>
				<PCard/>
			</Payment>
			<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>
			<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="stock_request"/>
		<xsl:apply-templates select="bestelopdracht"/>
</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="/">
		<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/><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->