<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                              xmlns:ns2021="VSR"
                              xmlns:ns1="VSR">
	<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
	<xsl:decimal-format name="european" decimal-separator="." grouping-separator=","/>
	<xsl:param name="mode"/>

	<xsl:template match="bestelopdracht">
		<!--Facilitor custom XSL template for cXML bestelopdracht-->
		<order>
			<unique_id><xsl:value-of select="id"/></unique_id>
      <created><xsl:value-of select="datum/jaar"/>-<xsl:value-of select="datum/maand"/>-<xsl:value-of select="datum/dag"/></created>
      <ordering_count>0</ordering_count>
      <ip></ip>
      <company>de Alliantie</company>
      <contact_initials></contact_initials>
      <street_delivery><xsl:value-of select="afleveradres/bezoek_adres"/></street_delivery>
      <street_invoice><xsl:value-of select="bedrijf/factuuradres/post_adres"/></street_invoice>
      <street_number_delivery></street_number_delivery>
      <street_number_invoice></street_number_invoice>
      <city_delivery><xsl:value-of select="afleveradres/bezoek_plaats"/></city_delivery>
      <city_invoice><xsl:value-of select="bedrijf/factuuradres/post_plaats"/></city_invoice>
      <company_delivery><xsl:value-of select="afleveradres/naam"/></company_delivery>
      <company_invoice><xsl:value-of select="bedrijf/factuuradres/naam"/></company_invoice>
      <contact_delivery><xsl:value-of select="bestelling/aanvrager/naam_full"/></contact_delivery>
      <contact_infix></contact_infix>
      <contact_invoice></contact_invoice>
      <contact_lastname></contact_lastname>
      <country_delivery><xsl:apply-templates select="afleveradres/bezoek_land"/></country_delivery>
      <country_invoice><xsl:apply-templates select="bedrijf/factuuradres/post_land"/></country_invoice>
      <email><xsl:value-of select="bestelling/aanvrager/email"/></email>
      <phone></phone>
      <postal_code_delivery><xsl:value-of select="afleveradres/bezoek_postcode"/></postal_code_delivery>
      <postal_code_invoice><xsl:value-of select="bedrijf/factuuradres/post_postcode"/></postal_code_invoice>
      <reference><xsl:value-of select="id"/></reference>
      <reference_comment></reference_comment>
      <reference_district></reference_district>
      <reference_number><xsl:value-of select="id"/></reference_number>
      <vat_number></vat_number>
      <contact></contact>
      <salutation></salutation>
      <order_slogan></order_slogan>
      <email_cc></email_cc>
      <street></street>
      <street_number></street_number>
      <postal_code></postal_code>
      <city></city>
      <mobile></mobile>
      <fax></fax>
			<xsl:for-each select="bestelopdrachtitem">
    			<items>
            <item_id><xsl:value-of select="bestelitem/srtdeel/artikel_nummer"/></item_id>
            <qty><xsl:value-of select="aantal"/></qty>
            <name><xsl:value-of select="bestelitem/srtdeel/omschrijving"/></name>
            <code></code>
            <description></description>
          </items>
      </xsl:for-each>
      <api_key>wwwdealliantieshopnl</api_key>
		</order>
	</xsl:template>

<xsl:template match="stock_request">
			<!--Facilitor custom XSL template for stock_request info -->
		<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2021="VSR">
        <SOAP-ENV:Body>
            <ns2021:get_stocks xmlns:ns2021="VSR">
            <product>
                <productcode><xsl:value-of select="part/number"/></productcode>
            </product>
            </ns2021:get_stocks>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
	</xsl:template>

  


  <xsl:template match="stock_response">
		<!--Facilitor custom XSL template for stock_response info -->
		
		<!-- Dit krijgen we retour aan voorraad-xml van Van Slobbe
        <?xml version="1.0" encoding="UTF-8"?>
    		<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    		<SOAP-ENV:Body>
    		<ns1:get_stocksResponse xmlns:ns1="VSR">
    		<stock_response>
            <product>
                <productcode>IBG1072292</productcode>
                <voorraad>10</voorraad>
            </product>
        </stock_response>
        </ns1:get_stocksResponse>
        </SOAP-ENV:Body>
        </SOAP-ENV:Envelope>
    -->
		
		<xsl:element name="facilitor">
    		<xsl:element name="stock_response">
        		<xsl:element name="part">
            		<xsl:element name="number">
        				<xsl:value-of select="product/productcode"/>
            		</xsl:element>
            		<xsl:element name="amount">
        				<xsl:value-of select="product/voorraad"/>
            		</xsl:element>
    		    </xsl:element>
    		</xsl:element>
		</xsl:element>
	</xsl:template>

  <!-- Uitpakken SOAP envelope -->
  <xsl:template match="SOAP-ENV:Envelope">
    <xsl:apply-templates select="SOAP-ENV:Body/ns1:get_stocksResponse/stock_response"/>
  </xsl:template>

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