NVN Export Orders XSLT transformation sample

Sample 1 – XML output grouped by Order ID

1/ add needed fields to export

Selection_409

2/ select “Export as” XML.

Selection_410

3/ Fill XSTL template and “Save”

Selection_411

That’s all.

.

.

Download example setting “nvn_settings.cfg” and import to module. Example setting is under “Setting 2

scr1

Selection_414

Selection_413

Used XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
  <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"> 
    <OrdersOut> 
      <xsl:for-each select="order[generate-id(.)=generate-id(key('groups',order_id))]"> 
        <OrderSummary> 
          <OrderId> 
            <xsl:value-of select="order_id/text()" /> 
          </OrderId> 
          <Orderdate> 
            <xsl:value-of select="date_add/text()" /> 
          </Orderdate> 
          <Items> 
              <xsl:for-each select="key('groups',order_id)"> 
                <ItemName> 
                  <xsl:value-of select="product_name/text()" /> 
                </ItemName> 
                <ItemQuantity> 
                  <xsl:value-of select="product_quantity/text()" /> 
                </ItemQuantity>             
              </xsl:for-each>       
          </Items> 
        </OrderSummary> 
      </xsl:for-each> 
    </OrdersOut> 
  </xsl:template> 
</xsl:stylesheet>

 

Sample output:

<OrdersOut>
  <OrderSummary>
    <OrderId>1</OrderId>
    <Orderdate>2015-08-20 17:25:33</Orderdate>
    <Items>
      <ItemName>Blouse</ItemName>
      <ItemQuantity>1</ItemQuantity>
      <ItemName>Printed Dress</ItemName>
      <ItemQuantity>1</ItemQuantity>
    </Items>
  </OrderSummary>
  <OrderSummary>
    <OrderId>2</OrderId>
    <Orderdate>2015-08-20 17:25:33</Orderdate>
    <Items>
      <ItemName>Blouse</ItemName>
      <ItemQuantity>1</ItemQuantity>
      <ItemName>Printed Summer Dress</ItemName>
      <ItemQuantity>1</ItemQuantity>
      <ItemName>Printed Chiffon Dress</ItemName>
      <ItemQuantity>1</ItemQuantity>
    </Items>
  </OrderSummary>
</OrdersOut>

 

Sample 2 – HTML output with images

setting is similar as in first sample, only add html extension for exported file:

Selection_416

Change XSTL:

Selection_417

Download example setting “nvn_settings.cfg” and import to module. Example setting is under “Setting 1

 

Used XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="order">

<xsl:variable name="image">
  <xsl:value-of select="image_link"/>
</xsl:variable>
<xsl:variable name="price" select="product_price"/>
<xsl:variable name="quant" select="product_quantity"/>
        
  <html>
    <head>
      <title>Order #<xsl:value-of select="order_id"/></title>
    </head>
    <body>
    <div style="width:600px; background-color:Lavender; border:2px solid Red;">
         <div style="float:right; background-color:#323438; border:2px solid Black;">
           <img src="{$image}" height="100" width="100"/>
         </div>
      <h2>Order ID #<xsl:value-of select="order_id"/>
          added: <xsl:value-of select="date_add"/></h2>

         <div style="width:70%; background-color:#fef9a1; border:1px solid Gray;">
          <span><b>Buyer: </b></span>
          <span style="color:Red;">
            <xsl:value-of select="first_name"/> <xsl:value-of select="last_name"/>
          </span>
          <p></p>
          <span><b>Product: </b></span>
          <span style="color:Blue;">
           <xsl:value-of select="product_name"/>
          </span>
          <p></p>
          <span><b>Product quantity: </b></span>
          <span style="color:Green;">
           <xsl:value-of select="product_quantity"/>
          </span>
          <p></p>
          <span><b>Product price: </b></span>
          <span style="color:Green;">
           <xsl:value-of select="product_price"/>
          </span>
         </div>
         <div style="width:100%; font-size: 28px; background-color:#b2fcd1; border-top:1px solid Gray;">
          <span><b>Product price * Product quantity: </b></span>
          <span style="color:Red;"><b>
           <xsl:value-of select="$price*$quant"/>
          </b></span>
         </div>         
    </div>
    <p>---------------------------------------------------------------</p>
    </body>
  </html>  
</xsl:template>

</xsl:stylesheet>

Sample output:

Selection_418

 

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

Transformation step by step tutorial You can find here: http://www.praotec.com/nvn-export-orders-simple-xslt-transformation-sample-step-by-step/

 

 

2 comments for “NVN Export Orders XSLT transformation sample

  1. 6.8.2016 at 9.49

    Admitedly, you lose the flexibility of the scripting solution, but I would argue that if your dialog engine is built with a robust collection of rules, the extra flexibility is unnecessary, and ultimately more trouble than it s worth.

    • kafa
      6.8.2016 at 11.47

      In truth, XSLT is not required in most case. Is useful only for special export. Usually normal export setting is sufficient. (scripting solution is still accessible via module extension)

Leave a Reply

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