xsl-list
[Top] [All Lists]

RE: re-ordering nodes/partial sort

2004-10-10 11:38:02
Hi David

Thanks for the answer(s). It is not a straighforward sort. Looking at in
terms of priority:

Bed & Breakfast             --> priority 1
Bed & Breakfast (child)     --> priority 2
Half Board                              --> priority 3
Half Board (child)              --> priority 4
Full Board                              --> priority 5
Full Board (child)              --> priority 6

All other <supp> nodes are output before the priority ones above (in
document order).

Kind regards.

--
Kevin


-----Original Message-----
From: M. David Peterson [mailto:m(_dot_)david(_at_)mdptws(_dot_)com]
Sent: 10 October 2004 17:38
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] re-ordering nodes/partial sort

Hey Kevin,

Does this have to be in document order of the input (or based on an
index
of
some sort) or is this something that can solved simply by using the
sort
element?  Something as simple as this...

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

<xsl:template match="/">
   <supplements>
   <xsl:apply-templates select="supplements/supp">
    <xsl:sort select="supp-desc"/>
   </xsl:apply-templates>
   </supplements>
</xsl:template>

<xsl:template match="supp">
   <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>

Will give you this...

<?xml version="1.0" encoding="UTF-8"?>
<supplements>
   <supp>
     <supp-desc>Balcony</supp-desc>
     <supp-price>8.00</supp-price>
   </supp>
   <supp>
     <supp-desc>Bed &amp; Breakfast</supp-desc>
     <supp-price>4.00</supp-price>
   </supp>
   <supp>
     <supp-desc>Bed &amp; Breakfast (child)</supp-desc>
     <supp-price>2.00</supp-price>
   </supp>
   <supp>
     <supp-desc>Full Board</supp-desc>
     <supp-price>60.00</supp-price>
   </supp>
   <supp>
     <supp-desc>Full Board (child)</supp-desc>
     <supp-price>30.00</supp-price>
   </supp>
   <supp>
     <supp-desc>Half Board</supp-desc>
     <supp-price>30.00</supp-price>
   </supp>
   <supp>
     <supp-desc>Half Board (child)</supp-desc>
     <supp-price>15.00</supp-price>
   </supp>
   <supp>
     <supp-desc>Sea View</supp-desc>
     <supp-price>10.00</supp-price>
   </supp>
</supplements>

But it seems that you have a requirement to sort based on doc order as
well?
Let me know if this is sufficient or if you need further help. The
indexed
solution is pretty straight forward as well but if this works, no need
to
further complicate the code if you don't have to.

Best regards,

<M:D/>


Kevin Bird wrote:
Hi

In the following structure I can receive 1 or many <supp> nodes.
Some of
the <supp> nodes need re-arranging depending on their <supp-desc>.
The
order is: Bed &amp; Breakfast, Bed &amp; Breakfast (child), Half
Board,
Half Board (child), Full Board and Full Board (child). Any <supp>
with a
<supp-desc> that is not one of the above appear before them in the
output.

Any suggestions would be greatly appreciated.

--INPUT--

<supplements>
    <supp>
            <supp-desc>Sea View</supp-desc>
            <supp-price>10.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Half Board</supp-desc>
            <supp-price>30.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Bed &amp; Breakfast</supp-desc>
            <supp-price>4.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Full Board</supp-desc>
            <supp-price>60.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Half Board (child)</supp-desc>
            <supp-price>15.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Full Board (child)</supp-desc>
            <supp-price>30.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Bed &amp; Breakfast (child)</supp-desc>
            <supp-price>2.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Balcony</supp-desc>
            <supp-price>8.00</supp-price>
    </supp>
</supplements>

--REQUIRED OUTPUT--

<supplements>
    <supp>
            <supp-desc>Sea View</supp-desc>
            <supp-price>10.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Balcony</supp-desc>
            <supp-price>8.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Bed &amp; Breakfast</supp-desc>
            <supp-price>4.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Bed &amp; Breakfast (child)</supp-desc>
            <supp-price>2.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Half Board</supp-desc>
            <supp-price>30.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Half Board (child)</supp-desc>
            <supp-price>15.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Full Board</supp-desc>
            <supp-price>60.00</supp-price>
    </supp>
    <supp>
            <supp-desc>Full Board (child)</supp-desc>
            <supp-price>30.00</supp-price>
    </supp>
</supplements>

Thanks.

--
Kevin




--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





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