[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: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Sun, 10 Oct 2004 11:30:37 -0700
xsl sort desc
Kevin,

Just so you have the info if you need it (and if you can be certain that if the 'supp-desc' element value contains a '(' then it is going to have a 'supp-desc' cousin with the same name minus the descriptor enclosed in '()') then the following will work as far as keeping things in document order and then making copies of all the siblings with the same name and sorting those ascending alphabetically (implied if not specified with the sort attribute)...

If there are other details that will determine whether or not an element should be included or excluded via the first apply-templates then this method won't work but this are not then this is a fairly simple way to accomplish what you want.

<?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[not(contains(supp-desc, '('))]"/>
</supplements>
</xsl:template>


  <xsl:template match="supp">
    <xsl:for-each select=". | ../supp[contains(supp-desc, current()/supp-desc)]">
    <xsl:sort select="supp-desc"/>
      <xsl:copy-of select="."/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Hope this helps!

<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.