[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: re-ordering nodes/partial sort

Subject: RE: re-ordering nodes/partial sort
From: "Kevin Bird" <kevin.bird@xxxxxxxxxxxxx>
Date: Sun, 10 Oct 2004 19:38:02 +0100
kevin bird
Hi David

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

Bed &amp; Breakfast		--> priority 1
Bed &amp; 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.david@xxxxxxxxxx]
> Sent: 10 October 2004 17:38
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.