NVN Export Orders – page of XSLT samples

Read how to apply samples: http://www.praotec.com/nvn-export-orders-xslt-transformation-sample/

Step by step sample: http://www.praotec.com/nvn-export-orders-simple-xslt-transformation-sample-step-by-step/

Sample 1

  • add needed fields into export

Selection_687

  • setup export format to xml

Selection_689

  • Fill XSLT stylesheet

Selection_688

  • use this XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml" version="1.0" />
<xsl:key use="order_id" match="/nvn_export_orders/order" name="groups"/>
<xsl:template match="/">
<xsl:apply-templates select="/nvn_export_orders" />
</xsl:template>
<xsl:template match="/nvn_export_orders">
<!-- FIRST ROW AND WRAPPER-->
<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd">
  <Orders>
      <xsl:for-each select="order[generate-id(.)=generate-id(key('groups',order_id))]">
      <!--COMMON VALUES HERE-->
    <Order type="V">
      <Description>Omschrijving</Description>
      <YourRef><xsl:value-of select="order_reference"/></YourRef>
      <Reference><xsl:value-of select="date_add"/></Reference>
      <OrderedBy>
        <Debtor code="debiteurennummer">
        </Debtor>
      </OrderedBy>
      <DeliverTo>
        <Debtor code="debiteurennummer">
        </Debtor>
        <Address>
          <Addressee>
            <Name><xsl:value-of select="delivery_firstname"/><xsl:text> </xsl:text><xsl:value-of select="delivery_lastname"/></Name>
          </Addressee>
          <AddressLine1><xsl:value-of select="delivery_address1"/></AddressLine1>
          <PostalCode><xsl:value-of select="delivery_postcode"/></PostalCode>
          <City><xsl:value-of select="delivery_city"/></City>
          <Country><xsl:attribute name="code"><xsl:value-of select="country_delivery_iso_code"/></xsl:attribute></Country>
        </Address>
      </DeliverTo>
      <InvoiceTo>
        <Debtor code="Debiteurennummer">
        </Debtor>
      </InvoiceTo>
      <DeliveryMethod><xsl:attribute name="code"><xsl:value-of select="carrier_name"/></xsl:attribute></DeliveryMethod>
      <Selection code="BU">
      </Selection>
              <xsl:for-each select="key('groups',order_id)">
              <!--ROWS ITEMS HERE-->
      <OrderLine><xsl:attribute name="lineNo"><xsl:value-of select="position()"/></xsl:attribute>
        <Item><xsl:attribute name="code"><xsl:value-of select="product_reference"/></xsl:attribute></Item>
        <Quantity><xsl:value-of select="product_quantity"/></Quantity>
      </OrderLine>
              </xsl:for-each>
    </Order>
      </xsl:for-each>
  </Orders>
</eExact>
  </xsl:template>
</xsl:stylesheet>

 output

<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd">
  <Orders>
    <Order type="V">
      <Description>Omschrijving</Description>
      <YourRef>XHRXENQBT</YourRef>
      <Reference>2015-10-07 10:03:05</Reference>
      <OrderedBy>
        <Debtor code="debiteurennummer"/>
      </OrderedBy>
      <DeliverTo>
        <Debtor code="debiteurennummer"/>
        <Address>
          <Addressee>
            <Name>Ka fa</Name>
          </Addressee>
          <AddressLine1>Ulice1</AddressLine1>
          <PostalCode>27711</PostalCode>
          <City>Nera</City>
          <Country code="CZ"/>
        </Address>
      </DeliverTo>
      <InvoiceTo>
        <Debtor code="Debiteurennummer"/>
      </InvoiceTo>
      <DeliveryMethod code="My carrier"/>
      <Selection code="BU"/>
      <OrderLine lineNo="1">
        <Item code="demo_3"/>
        <Quantity>1</Quantity>
      </OrderLine>
      <OrderLine lineNo="2">
        <Item code="demo_4"/>
        <Quantity>2</Quantity>
      </OrderLine>
      <OrderLine lineNo="3">
        <Item code="demo_7"/>
        <Quantity>2</Quantity>
      </OrderLine>
    </Order>
  </Orders>
</eExact>

Sample 2

XSLT:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes" method="xml" version="1.0" /> 
  <xsl:key use="order_id" match="/nvn_export_orders/order" name="groups"/> 
  <xsl:template match="/"> 
    <xsl:apply-templates select="/nvn_export_orders" /> 
  </xsl:template> 
  <xsl:template match="/nvn_export_orders"> 
    <nvn_export_orders> 
      <xsl:for-each select="order[generate-id(.)=generate-id(key('groups',order_id))]"> 
        <order> 
          <customer>
             <customer_firstname><xsl:value-of select="first_name/text()" /></customer_firstname>
             <customer_surname><xsl:value-of select="last_name/text()" /></customer_surname>
             <customer_id><xsl:value-of select="id_customer/text()" /></customer_id>
             <customer_email><xsl:value-of select="email/text()" /></customer_email>
          </customer>
          <details>
             <order_reference><xsl:value-of select="order_id/text()" /></order_reference>
             <!--<order_vat><xsl:value-of select="format-number((total_paid_tax_incl - total_paid_tax_excl),'#.###,00')" /></order_vat>-->
             <order_vat>0</order_vat>
             <order_total><xsl:value-of select="total_paid_tax_incl/text()" /></order_total>
          </details>
          <shipping>
             <shipping_price><xsl:value-of select="total_shippping_tax_excl/text()" /></shipping_price>
             <address>
                <company_name><xsl:value-of select="delivery_company/text()" /></company_name>
                <address_line_one><xsl:value-of select="delivery_address1/text()" /></address_line_one>
                <address_line_two><xsl:value-of select="delivery_address2/text()" /></address_line_two>
                <town><xsl:value-of select="delivery_city/text()" /></town>
                <postcode><xsl:value-of select="delivery_postcode/text()" /></postcode>
                <country_code><xsl:value-of select="country_delivery_iso_code/text()" /></country_code>
             </address>
          </shipping>
          <payment>
             <payment_method><xsl:value-of select="payment/text()" /></payment_method>
          </payment>
          <order_items>          
              <xsl:for-each select="key('groups',order_id)"> 
              <item>
                 <product_code><xsl:value-of select="product_reference/text()" /></product_code>
                 <quantity><xsl:value-of select="product_quantity/text()" /></quantity>
                 <price_per_unit><xsl:value-of select="product_price/text()" /></price_per_unit>
                 <warehouse>3</warehouse>                
              </item>                
              </xsl:for-each>       
          </order_items>
        </order> 
      </xsl:for-each>
    </nvn_export_orders> 
  </xsl:template> 
</xsl:stylesheet>

Output:

<nvn_export_orders>
  <order>
    <customer>
      <customer_firstname>John</customer_firstname>
      <customer_surname>DOE</customer_surname>
      <customer_id>1</customer_id>
      <customer_email>pub@prestashop.com</customer_email>
    </customer>
    <details>
      <order_reference>1</order_reference>
      <order_vat>0</order_vat>
      <order_total>55.000000</order_total>
    </details>
    <shipping>
      <shipping_price/>
      <address>
        <company_name>My Company</company_name>
        <address_line_one>16, Main street</address_line_one>
        <address_line_two>2nd floor</address_line_two>
        <town>Miami</town>
        <postcode>33133</postcode>
        <country_code>US</country_code>
      </address>
    </shipping>
    <payment>
      <payment_method>Payment by check</payment_method>
    </payment>
    <order_items>
      <item>
        <product_code>demo_2</product_code>
        <quantity>1</quantity>
        <price_per_unit>26.999852</price_per_unit>
        <warehouse>3</warehouse>
      </item>
      <item>
        <product_code>demo_3</product_code>
        <quantity>1</quantity>
        <price_per_unit>25.999852</price_per_unit>
        <warehouse>3</warehouse>
      </item>
    </order_items>
  </order>
  <order>
    <customer>
      <customer_firstname>John</customer_firstname>
      <customer_surname>DOE</customer_surname>
      <customer_id>1</customer_id>
      <customer_email>pub@prestashop.com</customer_email>
    </customer>
    <details>
      <order_reference>2</order_reference>
      <order_vat>0</order_vat>
      <order_total>75.900000</order_total>
    </details>
    <shipping>
      <shipping_price/>
      <address>
        <company_name>My Company</company_name>
        <address_line_one>16, Main street</address_line_one>
        <address_line_two>2nd floor</address_line_two>
        <town>Miami</town>
        <postcode>33133</postcode>
        <country_code>US</country_code>
      </address>
    </shipping>
    <payment>
      <payment_method>Payment by check</payment_method>
    </payment>
    <order_items>
      <item>
        <product_code>demo_2</product_code>
        <quantity>1</quantity>
        <price_per_unit>26.999852</price_per_unit>
        <warehouse>3</warehouse>
      </item>
      <item>
        <product_code>demo_6</product_code>
        <quantity>1</quantity>
        <price_per_unit>30.502569</price_per_unit>
        <warehouse>3</warehouse>
      </item>
      <item>
        <product_code>demo_7</product_code>
        <quantity>1</quantity>
        <price_per_unit>20.501236</price_per_unit>
        <warehouse>3</warehouse>
      </item>
    </order_items>
  </order>
</nvn_export_orders>

 

 

4 comments for “NVN Export Orders – page of XSLT samples

  1. MajorLaser
    13.5.2017 at 7.57

    Is it possible to ad the line on top of the xslt output file?

Leave a Reply

Your email address will not be published. Required fields are marked *