Created
June 17, 2021 18:14
-
-
Save jbelke/191d0ef8dde3937636bdb807ec27bb11 to your computer and use it in GitHub Desktop.
Order Export Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> <!-- XML Declaration, leave as is --> | |
<files> <!-- Files node, can contain multiple <file> nodes, each defining one output format --> | |
<file filename="orders_%d%_%m%_%Y%.csv"> <!-- File node, contains the actual XSL Template, with parameters filename and encoding (optional) --> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl"> <!-- The XSL Template begins here. Namespaces get defined. Leave as is. --> | |
<xsl:output method="text" encoding="UTF-8"/> <!-- The xsl:output directive defines settings that apply to the whole XSL Template. Method can be set to xml for example, encoding will be output for XML files into the XML declaration of the file. More parameters can be found here: http://www.w3schools.com/xsl/el_output.asp --> | |
<xsl:variable name="sepstart" select="'"'"/> <!-- A variable that can be accessed using $sepstart in the XSL Template. It contains " which is the representation of the " character. --> | |
<xsl:variable name="sepend" select="'",'"/> <!-- Again, a variable. This time with the " character as well as a comma. Whenever it is called, it will output: ", --> | |
<xsl:template match="/"> | |
<xsl:text>"Order Number","SKU","Quantity"
</xsl:text> <!-- This is the header line of the CSV file. It gets output once only, the 
 characters represent a line break that gets output after the header line. --> | |
<xsl:for-each select="objects/object"> <!-- for-each means that the template will loop through the objects/object nodes in the XML processed. So for every object (order, invoice, ...) the code below will be applied. --> | |
<xsl:for-each select="items/item"> <!-- Loop through items ordered --> | |
<!-- This means, loop through all items of an object and output the following: --> | |
<xsl:value-of select="$sepstart" /><xsl:value-of select="../../increment_id"/><xsl:value-of select="$sepend" /> <!-- The $sepstart variable outputs " to start a new field in the CSV file. Then using xsl:value-of select="../../increment_id" the "increment_id" field is pulled from the object level. ../../ means to get data from the "parent" level (we are looping through items and not through objects (orders). The $sepend variable then outputs ", to denote the end of the field in the CSV file. --> | |
<xsl:value-of select="$sepstart" /><xsl:value-of select="sku"/><xsl:value-of select="$sepend" /> <!-- Get the "sku" field on item level --> | |
<xsl:value-of select="$sepstart" /><xsl:value-of select="round(qty)"/> <!-- Get the "qty_ordered" field on item level and apply the round() function to it. --><xsl:value-of select="$sepend" /> | |
<xsl:text>
</xsl:text> <!-- Output a line break. --> | |
</xsl:for-each> <!-- End item foreach --> | |
</xsl:for-each> <!-- End object foreach --> | |
</xsl:template> | |
</xsl:stylesheet> | |
</file> | |
</files> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment