xsl-list
[Top] [All Lists]

RE: Sorting problem

2003-02-23 17:28:32
Hi Chris:

Your XML is not in the format you're expecting... removing attributes
for clarity:

        <DeliveryDays ... >
                <DeliveryMethod ...>
                        <Day ... />
                        <Day ... />
                </DeliveryMethod>
                <DeliveryMethod ... />
                        <Day ... />
                </DeliveryDays>

If you look on the second delivery method, you have the closing tag
inside the start tag.  The Day element below it is indented, but
logically it's the same level as DeliveryMethod, hence the unexpected
response.

HTH!

Dion

-----Original Message-----
From: crestall(_at_)amphire(_dot_)com [mailto:crestall(_at_)amphire(_dot_)com] 
Sent: Sunday, February 23, 2003 3:59 PM
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com

Hi All,

I'm stumped on this one.  I'm attempting to duplicate this xml but with
the <days> sorted by @sortID for each <DeliveryMethod>.  The first
sorting of <days> for the first <DeliveryMethod> works as it should
however <days> for the second <DeliveryMethod> are not output.  I've
tried various methods but cannot get the second grouping to output.  Any
suggestions:

----Sample XML-----
<CustomerDeliveryDays>
        <DeliveryDays Calculate="1" TimeOffset="0" MaxDaysOut="7">
                <DeliveryMethod Type="1" Desc="Standard (Truck)">
                        <Day OrderDate="0" DayIndex="4"
DeliveryTime="00:00" DeliveryDescription="" DeliveryDate="2/26/2003
12:00:00 AM" DateDifference="0" SortID="111"/>
                        <Day OrderDate="0" DayIndex="2"
DeliveryTime="00:00" DeliveryDescription="" DeliveryDate="2/24/2003
12:00:00 AM" DateDifference="0" SortID="63"/>
                        
                </DeliveryMethod>
                <DeliveryMethod Type="2" Desc="Will Call / Pickup "/>
                        <Day OrderDate="0" DayIndex="4"
DeliveryTime="00:00" DeliveryDescription="" DeliveryDate="2/26/2003
12:b00:00 AM" DateDifference="0" SortID="111"/>
                        <Day OrderDate="0" DayIndex="2"
DeliveryTime="00:00" DeliveryDescription="" DeliveryDate="2/24/2003
12:00:00 AM" DateDifference="0" SortID="63"/>
                </DeliveryDays>
</CustomerDeliveryDays>


----XSL----
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
        <xsl:template match="/">
                <CustomerDeliveryDays>
                        <xsl:apply-templates
select="CustomerDeliveryDays/DeliveryDays"/>
                </CustomerDeliveryDays>
        </xsl:template>         
        <xsl:template match="CustomerDeliveryDays/DeliveryDays">
                <DeliveryDays>
                        <xsl:call-template name="AddAllAttributes" />
                        <xsl:for-each select="DeliveryMethod">
                                <DeliveryMethod>
                                        <xsl:call-template
name="AddAllAttributes" />
                                        <xsl:call-template
name="GetDays" />                               
                                </DeliveryMethod>
                        </xsl:for-each>
                </DeliveryDays>
        </xsl:template> 
        <xsl:template name="GetDays">
                <xsl:for-each select="Day">
                        <xsl:sort select="@sortID" order="ascending"/>
                                <Day>
                                        <xsl:call-template
name="AddAllAttributes" />
                                </Day>  
                </xsl:for-each> 
        </xsl:template>
        <xsl:template name="AddAllAttributes">
                <xsl:for-each select="@*">
                        <xsl:attribute name="{name(.)}"><xsl:value-of
select="."/></xsl:attribute>
                </xsl:for-each>  
        </xsl:template>                 
</xsl:stylesheet>

Thanks in advance,

Chris Restall

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>