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

RE: Sorting based on string length in an element

Subject: RE: Sorting based on string length in an element
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 22 Jul 2005 23:28:48 +0100
sort by string length
<xsl:for-each select="book/desc">
  <xsl:sort select="string-length(.)" data-type="number"
order="descending"/>
  <xsl:if test="position() &lt; 3">
    <xsl:copy-of select="."/>
  </xsl:if>
</xsl:for-each>

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Karl Koch [mailto:TheRanger@xxxxxxx] 
> Sent: 22 July 2005 23:14
> To: Mulberry list
> Subject:  Sorting based on string length in an element
> 
> Hello XSLT experts,
> 
> I have the following kind of content:
> 
> <bookshelf>
>   <book><desc>description AAAA</desc></book>
>   <book><desc>description AA</desc></book>
>   <book><desc>description AAA</desc></book>
>   <book><desc>description A</desc></book>
> </bookshelf>
> 
> I am looking for one stylesheet that sorts the booklist in 
> descending order
> depending on the length of the <desc> element. The result 
> would look like
> this:
> 
> <bookshelf>
>   <book><desc>description AAAA</desc></book>
>   <book><desc>description AAA</desc></book>
>   <book><desc>description AA</desc></book>
>   <book><desc>description A</desc></book>
> </bookshelf>
> 
> Also I would like to have a slight modification of that which 
> cuts the list
> at a certain position (e.g. pos = 2) which would give me this result:
> 
> <bookshelf>
>   <book><desc>description AAAA</desc></book>
>   <book><desc>description AAA</desc></book>
> </bookshelf>
> 
> How would this modified stylesheet look like assuming that it 
> should also
> work properly in case the list is shorter than pos?
> 
> Kind Regards,
> Karl
> 
> -- 
> 5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
> +++ GMX - die erste Adresse fo?=r Mail, Message, More +++

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.