1/ Add needed fields into export. You can add also unwanted and unsorted fields, does not affect in this case.
2/ Set up OPTIONS: we will need raw data for XLST transform (1), and in this example we will need output CSV format file (2).
3/ 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>
</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:
<?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>
</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,'Order ID',$quo,';',$quo,'Product Ref.',$quo,';',$quo,'Product quant.',$quo,';',$quo,'Product name',$quo,';;' ,$quo,'Company',$quo,';',$quo,'Firstname Lastname.',$quo,';',$quo,'Address1',$quo,';',$quo,'Address2',$quo,';',$quo,'Poscode',$quo,';',$quo,'City',$quo ,$newline)"/> <xsl:for-each select="order[generate-id(.)=generate-id(key('groups',order_id))]"> <!--COMMON VALUES HERE--> <xsl:value-of select="concat( order_id,';;;;' ,$quo,'INVOICE ADDRESS:',$quo,';' ,$quo,invoice_company,$quo,';' ,$quo,invoice_firstname,' ',invoice_lastname,$quo,';' ,$quo,invoice_address1,$quo,';' ,$quo,invoice_address2,$quo,';' ,$quo,invoice_postcode,$quo,';',$quo,invoice_city,$quo ,$newline)"/> <xsl:value-of select="concat( order_id,';;;;' ,$quo,'DELIVERY ADDRESS:',$quo,';' ,$quo,delivery_company,$quo,';' ,$quo,delivery_firstname,' ',delivery_lastname,$quo,';' ,$quo,delivery_address1,$quo,';' ,$quo,delivery_address2,$quo,';' ,$quo,delivery_postcode,$quo,';',$quo,delivery_city,$quo ,$newline)"/> <xsl:for-each select="key('groups',order_id)"> <!--ROWS ITEMS HERE--> <xsl:value-of select="concat( order_id,';' ,$quo,product_reference,$quo,';' ,$quo,product_quantity,$quo,';' ,$quo,product_name,$quo ,$newline)"/> </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 this xlsx stylesheet into module “XML transformation – XSLT stylesheet” and save setting.
Export and save csv file.
Sample output opened in Calk
For more samples visit this page: http://www.praotec.com/nvn-export-orders-page-of-xslt-samples/
