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

Re: a sorting conundrum

Subject: Re: a sorting conundrum
From: Kevin Rodgers <kevin.rodgers@xxxxxxx>
Date: Thu, 3 Mar 2005 08:43:50 -0700
alphabetical conundrum
John Fitzgibbon writes:
> I am attempting to sort an a list of personal names. All of the names
> consist of either a first name followed by a last name or of a last name
> only (there are no middle names). Both parts of the name, when present,
> are enclosed within the one tag (span) which has a class='person'
> attribute, the same tag is used to enclose a last name only. I am
> attempting to sort by last name like so
> 
> <xsl:for-each select="html/body//span[@class='person']">
> <xsl:sort select="substring-after(., ' ')"/>
> <xsl:sort select="."/>
> <xsl:sort select="substring-before(., ' ')"/>
> 
> The problem is that names consisting of a last name only appear first in
> my alphabetical sequence and are sorted; these are followed by names
> with a first name and a last name and these are also sorted. I require
> one alphabetical list rather than two.
> 
> Can this be done in one fell swoop, without having to write an XSL style
> sheet for the file consisting of two alphabetical sequences?

How about (in XSLT 2.0):

<xsl:sort select="if (contains(., ' ')
                  then substring-after(., ' ')
                  else ."/>
<xsl:sort select="if (contains(., ' ')
                  then substring-before(., ' ')
                  else ''"/>

-- 
Kevin Rodgers

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.