Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Search
Search


Forum Index » Templates

Post new topic   Reply to topic
Looping though Shipments (only recent shipment)
View previous topic :: View next topic  
Author Message
rscof



Joined: 08 Feb 2004
Posts: 80

PostPosted: Mon Aug 29, 2005 9:01 am    Post subject: Looping though Shipments (only recent shipment) Reply with quote

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']) &gt; 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
View user's profile Visit poster's website MSN Messenger
Wes
Site Admin


Joined: 07 Oct 2002
Posts: 7427

PostPosted: Mon Aug 29, 2005 1:14 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
rscof



Joined: 08 Feb 2004
Posts: 80

PostPosted: Mon Aug 29, 2005 1:44 pm    Post subject: Reply with quote

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 &gt; 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
View user's profile Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index » Templates All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  

Powered by phpBB © 2001, 2002 phpBB Group