 |
| View previous topic :: View next topic |
| Author |
Message |
rscof
Joined: 08 Feb 2004 Posts: 80
|
Posted: Mon Aug 29, 2005 9:01 am Post subject: Looping though Shipments (only recent shipment) |
|
|
Just started modifying my old templates to use XSL and could use a little help please. My export CSV file is used for upload into VC Order Status module and needs to look like:
<OrderNumber>,OrderStatus>,<ServiceUsed>,TrackingNumber>,<OrderNotes>&nl;
<OrderNumber>,<ItemID>,<ItemStatus>
The first line is the order data with nunmber, order status and tracking data (if present)and all subsequent lines related to the order number are the items
My problem is that if more that one shipment has occured on different days (some my be voided or not) how do I select the most recent shipment data. I only want the current (Voided=false) shipment data.
Here is my mess...help would be appreciated
<xsl:for-each select="//Order">
<xsl:value-of select="Number" /><xsl:text>,</xsl:text>
<xsl:text>,</xsl:text>
<xsl:value-of select="Status" /><xsl:text>,</xsl:text>
<xsl:if test="count(//Order/Shipment[IsProcessed = 'true']) = 0">
<xsl:text>,</xsl:text>
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:if test="count(//Order/Shipment[IsProcessed = 'true']) > 1">
<xsl:for-each select="//Order/Shipment">
<xsl:if test="UPS/Voided = 'true'">
<xsl:text>,</xsl:text>
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:if test="UPS/Voided = 'false'">
<xsl:value-of select="ServiceUsed" /><xsl:text>,</xsl:text>
<xsl:value-of select="TrackingNumber" /><xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:if>
<xsl:value-of select="Notes" /><xsl:text>&nl;</xsl:text>
<xsl:for-each select="//Order/Item">
<xsl:value-of select="../Number" /><xsl:text>,</xsl:text>
<xsl:value-of select="@ID" /><xsl:text>,</xsl:text>
<xsl:value-of select="Status" /><xsl:text>&nl;</xsl:text>
</xsl:for-each>
</xsl:for-each> |
|
| Back to top |
|
Wes Site Admin
Joined: 07 Oct 2002 Posts: 7427
|
Posted: Mon Aug 29, 2005 1:14 pm Post subject: |
|
|
Hello,
We have an XSL template on file that should work with the VC Order Status Export system. Please see the template code below.
| Code: | <!-- -->
<!-- Start of processing -->
<!-- -->
<xsl:template match="/">
<xsl:text>&nl;</xsl:text>
<xsl:for-each select="//Order">
<xsl:sort select="Number" data-type="number" order="ascending" />
<xsl:value-of select="Number" /><xsl:text>,,</xsl:text>
<xsl:value-of select="Status" />
<xsl:for-each select="Shipment[IsProcessed = 'true']">
<xsl:if test="not(UPS/Voided) or UPS/Voided = 'false'">
<xsl:text>,</xsl:text>
<xsl:value-of select="ServiceUsed" /><xsl:text>,</xsl:text>
<xsl:value-of select="TrackingNumber" />
</xsl:if>
</xsl:for-each>
<xsl:text>,</xsl:text>
<xsl:value-of select="Notes" /><xsl:text>,</xsl:text>
<xsl:text>&nl;</xsl:text>
<xsl:for-each select="Item">
<xsl:value-of select="../Number" /><xsl:text>,</xsl:text>
<xsl:value-of select="Miva/LineID" /><xsl:text>,</xsl:text>
<xsl:value-of select="Status" />
<xsl:text>&nl;</xsl:text>
</xsl:for-each>
<xsl:text>&nl;</xsl:text>
</xsl:for-each>
</xsl:template> |
For the issue you described you might try adding a sort command in the for-each loop for selecting the processed and non voided shipment.
Please let us know if you have further questions.
Thanks,
Wes
Interapptive, Inc. |
|
| Back to top |
|
rscof
Joined: 08 Feb 2004 Posts: 80
|
Posted: Mon Aug 29, 2005 1:44 pm Post subject: |
|
|
Thanks Wes, I added this snippet to your template to select the most current shipment, and only one.
<!-- Just output the commas if no shipments found -->
<xsl:variable name="shipments" select="count(//Order/Shipment[IsProcessed = 'true'])" />
<xsl:if test="$shipments = 0">
<xsl:text>,</xsl:text>
<xsl:text>,</xsl:text>
</xsl:if>
<!-- If more than one shipment is found, always select the last -->
<!-- (most current) shipment in the loop -->
<xsl:if test="$shipments > 0">
<xsl:for-each select="//Order/Shipment[$shipments]">
<!-- Could have processed shipments that have been voided, if true -->
<!-- just output the commas for the CSV file -->
<xsl:if test="UPS/Voided = 'true'">
<xsl:text>,</xsl:text>
<xsl:text>,</xsl:text>
</xsl:if> |
|
| Back to top |
|
|
|
 |
 |
Powered by phpBB © 2001, 2002 phpBB Group
|
 |
|