NVN Export Orders – simple XSLT transformation – sample 3 step by step

1/ Add needed fields into export. You can add also unnecessary fields, in different  sequence, does not affect in this case.

Selection_704

3/ Set up FILTERS, for example only orders with invoice.

Selection_698

 

3/ Set up OPTIONS: we will need raw data for XLST transform (1), and in this example we will need output XML format file (2).

4/ Fill XLST transformation structure.

Here is basic XSLT structure for grouping Orders by Order ID:

<?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="no" indent="yes" method="xml" version="1.0" encoding="UTF-8" />
<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">

<xsl:variable name="set" select="/nvn_export_orders/order" />
<xsl:variable name="count" select="count($set)" /> <!--TOTAL_ITEMS COUNTER--> 
 
<!-- FIRST ROW AND WRAPPER-->
<ORDERS xmlns:od="http://www.w3.org/2001/XMLSchema-instance">

      <TOTAL_ITEMS><xsl:value-of select="$count" /></TOTAL_ITEMS>
      <xsl:for-each select="order[generate-id(.)=generate-id(key('groups',order_id))]"><!--ORDER CYCLE-->
      <ORDER>
         <!--COMMON VALUES HERE-->
 
         <ORDER_NO><xsl:value-of select="order_id" /></ORDER_NO>
         <CUSTOMER_EMAIL><xsl:value-of select="email" /></CUSTOMER_EMAIL>
 
              <ITEMS>
                  <xsl:for-each select="key('groups',order_id)"><!--ITEM CYCLE-->
                  <!--ROWS ITEMS HERE-->
                  <ITEM>
                      <ROW><xsl:value-of select="position()"/></ROW>
                      <PRODUCT_NAME><xsl:value-of select="product_name" /></PRODUCT_NAME>
                      <QUANTITY><xsl:value-of select="product_quantity" /></QUANTITY>
                  </ITEM>
                  </xsl:for-each><!--ITEM CYCLE END-->
              </ITEMS>
      </ORDER>

      <ORDERCOUNT><xsl:value-of select="position()"/></ORDERCOUNT>
      </xsl:for-each><!--ORDER CYCLE END-->

</ORDERS><!--WRAPPER END-->
 
  </xsl:template>
</xsl:stylesheet>

Copy and paste this xlsx stylesheet into module “XML transformation – XSLT stylesheet” and save setting.

Selection_699

TIP: For better edit is recommended use external editor with syntax highlighting and save backup of xsl stylesheet

Explanatory notes:

Text between <!–  –> is commentary and is not used for transformation.

Values insert using syntax <xsl:value-of select=”field_key” /> where “field_key” are keys from “List of XML tags”

For example <PRODUCT_NAME><xsl:value-of select=”product_name” /></PRODUCT_NAME>

xlstedit

 

Export and save XML file.

Selection_704

Sample output.

<?xml version="1.0" encoding="UTF-8"?>
<ORDERS xmlns:od="http://www.w3.org/2001/XMLSchema-instance">
  <TOTAL_ITEMS>3</TOTAL_ITEMS>
  <ORDER>
    <ORDER_NO>1</ORDER_NO>
    <CUSTOMER_EMAIL>test@rere.ts</CUSTOMER_EMAIL>
    <ITEMS>
      <ITEM>
        <ROW>1</ROW>
        <PRODUCT_NAME>Ontario - kamizelka pikowana</PRODUCT_NAME>
        <QUANTITY>1</QUANTITY>
      </ITEM>
    </ITEMS>
  </ORDER>
  <ORDERCOUNT>1</ORDERCOUNT>
  <ORDER>
    <ORDER_NO>2</ORDER_NO>
    <CUSTOMER_EMAIL>test@rere.ts</CUSTOMER_EMAIL>
    <ITEMS>
      <ITEM>
        <ROW>1</ROW>
        <PRODUCT_NAME>EMAMODA DRESS - BLUE 8711-3 - Size : S</PRODUCT_NAME>
        <QUANTITY>1</QUANTITY>
      </ITEM>
      <ITEM>
        <ROW>2</ROW>
        <PRODUCT_NAME>EMAMODA DRESS - Fuchsia 8711-2 - Size : S</PRODUCT_NAME>
        <QUANTITY>1</QUANTITY>
      </ITEM>
    </ITEMS>
  </ORDER>
  <ORDERCOUNT>2</ORDERCOUNT>
</ORDERS>

 

Example 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="no" indent="yes" method="xml" version="1.0" encoding="UTF-8" />
<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">

<xsl:variable name="set" select="/nvn_export_orders/order" />
<xsl:variable name="count" select="count($set)" />

<!-- FIRST ROW AND WRAPPER-->
<commandes xmlns:od="http://www.w3.org/2001/XMLSchema-instance">
<TOTAL_ITEMS><xsl:value-of select="$count" /></TOTAL_ITEMS>
      <xsl:for-each select="order[generate-id(.)=generate-id(key('groups',order_id))]"><!--ORDER CYCLE-->
      <CC_ENTETE_10>
         <!--COMMON VALUES HERE-->

                  <DEPOSANT>XXX</DEPOSANT>
                  <SHOP>YYY</SHOP>
                  <SITE>0</SITE>
                  <COMMANDE><xsl:value-of select="order_id" /></COMMANDE>
                  <COMMANDE_CLIENT><xsl:value-of select="order_id" /></COMMANDE_CLIENT>
                  <COMMANDE_N3><xsl:value-of select="order_reference" /></COMMANDE_N3>
                  <TYPECDE>WEB</TYPECDE>
                  <NBLIG_N3>2</NBLIG_N3>
                  <TYPE_TRANS>100</TYPE_TRANS>
                  <CODETRANS></CODETRANS>
                  <NOMTRANS></NOMTRANS>
                  <POIDS_CHOIX_TPT>0.6</POIDS_CHOIX_TPT>
                  <HCREATN3_CDE><xsl:value-of select="date_add" /></HCREATN3_CDE>
                  <CADEAU>0</CADEAU>
                  <CADEAU_MSG></CADEAU_MSG>
                  <ALERT_CLT>0</ALERT_CLT>
                  <TOTAL_TTC>32.99</TOTAL_TTC>
                  <MODE_PAIEMENT><xsl:value-of select="payment" /></MODE_PAIEMENT>
                  <DPREVUE_CDE></DPREVUE_CDE>
                  <BLOCAGE_INTERFACE></BLOCAGE_INTERFACE>
                  <DDEBLOCAGE></DDEBLOCAGE>
                  <BLOCAGE_COMMENT></BLOCAGE_COMMENT>
                  <DLIV_CDE></DLIV_CDE>
                  <INFOENTLIV1></INFOENTLIV1>
                  <INFOENTLIV2></INFOENTLIV2>
                  <INFOENTLIV3></INFOENTLIV3>
                  <MODELIV></MODELIV>
                  <INCOTERM></INCOTERM>
                  <CODECLIENT_LIV><xsl:value-of select="id_address_delivery" /></CODECLIENT_LIV>
                  <CODE_LANGUE_LIV>fr</CODE_LANGUE_LIV>
                  <NOMCLIENT_LIV><xsl:value-of select="delivery_lastname" /></NOMCLIENT_LIV>
                  <PRENOMCLIENT_LIV><xsl:value-of select="delivery_firstname" /></PRENOMCLIENT_LIV>
                  <SOCIETECLIENT_LIV><xsl:value-of select="delivery_company" /></SOCIETECLIENT_LIV>
                  <ADRESSE1_LIV><xsl:value-of select="delivery_address1" /></ADRESSE1_LIV>
                  <ADRESSE2_LIV><xsl:value-of select="delivery_address2" /></ADRESSE2_LIV>
                  <ADRESSE3_LIV></ADRESSE3_LIV>
                  <AUTRES_INFO_LIV></AUTRES_INFO_LIV>
                  <CODEPOSTAL_LIV><xsl:value-of select="delivery_postcode" /></CODEPOSTAL_LIV>
                  <VILLE_LIV><xsl:value-of select="delivery_city" /></VILLE_LIV>
                  <CODEPAYS_LIV><xsl:value-of select="country_delivery_iso_code" /></CODEPAYS_LIV>
                  <PAYS_LIV><xsl:value-of select="delivery_country" /></PAYS_LIV>
                  <CONTACT_LIV></CONTACT_LIV>
                  <TEL_LIV><xsl:value-of select="delivery_phone" /></TEL_LIV>
                  <FAX_LIV></FAX_LIV>
                  <MOBILE_LIV><xsl:value-of select="delivery_mobilephone" /></MOBILE_LIV>
                  <EMAIL_LIV><xsl:value-of select="email" /></EMAIL_LIV>
                  <CODE_PT_RELAIS>12005</CODE_PT_RELAIS>
                  <CODE_RESEAU_RELAIS>R12</CODE_RESEAU_RELAIS>
                  <CODECLIENT_FACT><xsl:value-of select="id_address_invoice" /></CODECLIENT_FACT>
                  <CODE_LANGUE_FACT>fr</CODE_LANGUE_FACT>
                  <NOMCLIENT_FACT><xsl:value-of select="invoice_lastname" /></NOMCLIENT_FACT>
                  <PRENOMCLIENT_FACT><xsl:value-of select="invoice_firstname" /></PRENOMCLIENT_FACT>
                  <SOCIETECLIENT_FACT><xsl:value-of select="invoice_company" /></SOCIETECLIENT_FACT>
                  <ADRESSE1_FACT><xsl:value-of select="invoice_address1" /></ADRESSE1_FACT>
                  <ADRESSE2_FACT><xsl:value-of select="invoice_address2" /></ADRESSE2_FACT>
                  <ADRESSE3_FACT></ADRESSE3_FACT>
                  <AUTRES_INFO_FACT></AUTRES_INFO_FACT>
                  <CODEPOSTAL_FACT><xsl:value-of select="invoice_postcode" /></CODEPOSTAL_FACT>
                  <VILLE_FACT><xsl:value-of select="invoice_city" /></VILLE_FACT>
                  <CODEPAYS_FACT><xsl:value-of select="country_invoice_iso_code" /></CODEPAYS_FACT>
                  <PAYS_FACT><xsl:value-of select="invoice_country" /></PAYS_FACT>
                  <CONTACT_FACT></CONTACT_FACT>
                  <TEL_FACT><xsl:value-of select="invoice_phone" /></TEL_FACT>
                  <FAX_FACT></FAX_FACT>
                  <MOBILE_FACT><xsl:value-of select="invoice_mobilephone" /></MOBILE_FACT>
                  <EMAIL_FACT><xsl:value-of select="email" /></EMAIL_FACT>
                  <COMMENTBP></COMMENTBP>
                  <COMMENTBL></COMMENTBL>
                  <COMMENTBE></COMMENTBE>
                  <REDUC_CODE></REDUC_CODE>
                  <REDUC_TYPE></REDUC_TYPE>
                  <REDUC_VAL></REDUC_VAL>
                  <REDUC_MSG></REDUC_MSG>
                  <REDUC_FV></REDUC_FV>
                  <REF_ASILAGE></REF_ASILAGE>
                  <QTE_ASILAGE></QTE_ASILAGE>

                  <xsl:for-each select="key('groups',order_id)"><!--ITEM CYCLE-->
                  <!--ROWS ITEMS HERE-->
                  <CC_LIGNE_10>
                            <DEPOSANT>XXX</DEPOSANT>
                            <SHOP>YYY</SHOP>
                            <SITE>0</SITE>
                            <ROW><xsl:value-of select="position()"/></ROW>
                            <COMMANDE><xsl:value-of select="order_id" /></COMMANDE>
                            <LIG_CDE>1</LIG_CDE>
                            <REFERENCE><xsl:value-of select="product_reference" /></REFERENCE>
                            <DESIGNATION_LIG><xsl:value-of select="product_name" /></DESIGNATION_LIG>
                            <QTECDEE_LIGCDE>1</QTECDEE_LIGCDE>
                            <STOCK></STOCK>
                            <PUHT_VENTE>250.2</PUHT_VENTE>
                            <DEVISE>EUR</DEVISE>
                            <INFOLIGLIV1></INFOLIGLIV1>
                            <INFOLIGLIV2></INFOLIGLIV2>
                            <INFOLIGLIV3></INFOLIGLIV3>
                            <CODE_TVA>0</CODE_TVA>     
                  </CC_LIGNE_10>
                  </xsl:for-each><!--ITEM CYCLE END-->
      </CC_ENTETE_10>
      <ORDERCOUNT><xsl:value-of select="position()"/></ORDERCOUNT>
      </xsl:for-each><!--ORDER CYCLE END-->
</commandes><!--WRAPPER END-->

  </xsl:template>
</xsl:stylesheet>

For more samples visit this page: http://www.praotec.com/nvn-export-orders-page-of-xslt-samples/

 

Leave a Reply

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