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

RE: Aberrant Alphabetizing.

Subject: RE: Aberrant Alphabetizing.
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Fri, 7 Mar 2003 12:05:21 -0000
alphabetizing
> I have run into something (embarrassingly) unexpected, using 
> sort to alphabetize

Hi Wendy,

Unfortunately you have also fallen into the for-each trap... using <xsl:for-each select="."> as the first child of a matching template will always select just one node - the element that it is being matched against.

What I think you should be doing is sorting the <book> child nodes of whatever parent they have by title, something like:
 
<xsl:template match="insert-parent-of-book-here">
  <xsl:apply-templates select="book">
    <xsl:sort select="title"/>
  </xsl:apply-templates>
</xsl:template>

Think of it as building a list of nodes to process using <xsl:apply-templates select="..."/>, and then sorting them using <xsl:sort/>

cheers
andrew

> -----Original Message-----
> From: Wendy McFarland [mailto:wmcfarla@xxxxxxx]
> Sent: 07 March 2003 11:40
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Aberrant Alphabetizing.
> 
> 
> I have run into something (embarrassingly) unexpected, using 
> sort to alphabetize
> book titles to be printed in a catalog. The sort is working 
> pefectly for most of
> the books. But here are 5 examples of incorrect sorting (that 
> were, sigh,
> pointed out to me by the client):
> 
> Computers at Risk: Safe Computing in the Information Age
>      (should be 2nd)
> 
> Computer Science and Artificial Intelligence
>      (should be 1st)
> 
> Effectiveness of the United States Advanced Battery Consortium as a
> Government-Industry Partnership
>      (should be 5th)
> 
> Effective Services for Young Children: Report of a Workshop
>      (should be 4th)
> 
> Effect of Environment on Nutrient Requirements of Domestic Animals
>      (should be 3rd)
> 
> 
> ---- The XSLT -----------------
> <xsl:template match="book">
>      <xsl:for-each select=".">
>           <xsl:sort select="title"/>
>           <xsl:apply-templates select="title"/>
>      </xsl:for-each>
> </xsl:template>
> -------------------------------
> 
> ---- The XML ------------------
> <book>
>      <title>Computers at Risk: Safe Computing in the 
> Information Age</title>
> </book>
> <book>
>      <title>Computer Science and Artificial Intelligence</title>
> </book>
> <book>
>      <title>Effectiveness of the United States Advanced 
> Battery Consortium as a
> Government-Industry Partnership</title>
> </book>
> <book>
>      <title>Effective Services for Young Children: Report of 
> a Workshop</title>
> </book>
> <book>
>      <title>Effect of Environment on Nutrient Requirements of Domestic
> Animals</title>
> </book>
> -------------------------------
> 
> 
> Can anyone help me understand why the alphabetizing doesn't 
> come out as
> expected?
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> 
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.458 / Virus Database: 257 - Release Date: 24/02/2003
>  
> 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.458 / Virus Database: 257 - Release Date: 24/02/2003
 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.