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

1/ Add needed fields into export. You can add also unwanted and unsorted fields, does not affect in this case.

Selection_704

 

3/ Set up FILTERS: in this sample we will only orders with invoice (1), and sorted by invoice number (2).

Selection_707

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

Selection_677

4/ Fill XLST transformation structure.

Here is basic structure (without data) 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 method="text" omit-xml-declaration="yes" indent="no"/><!-- IMPORTANT - WE NEED CSV OUTPUT -->
<xsl:variable name="newline"><xsl:text>&#xA;</xsl:text></xsl:variable><!-- CRLF NEED IN CSV OUTPUT -->
<xsl:variable name="quo"><xsl:text>"</xsl:text></xsl:variable><!-- QUOTES NEED IN CSV OUTPUT -->
  <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">
  <!--COLUMNS TITLES FIRST ROW--> 
     
      <xsl:for-each select="order[generate-id(.)=generate-id(key('groups',order_id))]">
      <!--COMMON VALUES HERE--> 
    
              <xsl:for-each select="key('groups',order_id)">
              <!--ROWS ITEMS HERE--> 

              </xsl:for-each>       
      </xsl:for-each>
  </xsl:template> 
</xsl:stylesheet>

Now we insert data fields into this structure:

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

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/><!-- IMPORTANT - WE NEED CSV OUTPUT -->
<xsl:variable name="newline"><xsl:text>&#xA;</xsl:text></xsl:variable><!-- CRLF NEED IN CSV OUTPUT -->
<xsl:variable name="quo"><xsl:text>"</xsl:text></xsl:variable><!-- QUOTES NEED IN CSV OUTPUT -->
  <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">
  <!--COLUMNS TITLES FIRST ROW--> 
           <xsl:value-of select="concat(
                    $quo,'Invoice',$quo,';',$quo,'Date',$quo,';',$quo,'Paid excl VAT',$quo,';',$quo,'Paid incl VAT',$quo,';',$quo,'Customer name',$quo,';',$quo,'Product',$quo,';',$quo,'Quantity',$quo       
                    ,$newline)"/>       
      <xsl:for-each select="order[generate-id(.)=generate-id(key('groups',order_id))]">
      <!--COMMON VALUES HERE--> 
           <xsl:value-of select="concat(
                    invoice_number,';'
                    ,$quo,invoice_date,$quo,';'
                    ,$quo,total_price_tax_excl,$quo,';'
                    ,$quo,total_price_tax_incl,$quo,';'
                    ,$quo,invoice_firstname,' ',invoice_lastname,$quo,';'
                    ,$quo,product_name,$quo,';'
                    ,$quo,product_quantity,$quo,';'
                    ,$newline)"/>     
              <xsl:for-each select="key('groups',order_id)">
              <!--ROWS ITEMS HERE-->
                <xsl:if test="position() != 1">
                   <xsl:value-of select="concat(
                        ';;;;;'
                       ,$quo,product_name,$quo,';'
                       ,$quo,product_quantity,$quo,';'
                       ,$newline)"/>
                </xsl:if>
              </xsl:for-each>       
      </xsl:for-each>
  </xsl:template> 
</xsl:stylesheet>

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

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

Selection_705

Export and save csv file.

Selection_680

Sample output opened in Calk

orders_2017-03-02_16h28m45s_1O1dU2Y-xml.csv (read-only) - LibreOffice Calc_706

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

2 comments for “NVN Export Orders – simple XSLT transformation – sample 2 step by step

  1. Marinov
    20.4.2018 at 5.05

    I need to export all invoices from a certain period of time for accounting purposes – can this be done with that module ?

    • ka fa
      20.4.2018 at 6.15

      Hello,
      yes, it is possible. But not in pdf format, only csv, excel xls/xlsx, html, XML.
      If your accounting program support any special input format, send me sample.

Leave a Reply

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