xsl-list
[Top] [All Lists]

RE: Aberrant Alphabetizing.

2003-03-07 04:56:20
Hi Wendy,

You are matching on "book", then doing a "for" loop over a single
node (select="."), then sorting that single node (which is a waste
of time). I guess you wanted something like this:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:template match="books">
    <xsl:apply-templates select="book">
      <xsl:sort select="title"/>
    </xsl:apply-templates>
  </xsl:template>
  
  <xsl:template match="book">
    <xsl:apply-templates select="title"/>
  </xsl:template>
</xsl:stylesheet>

Rgds,

Dan.

-----Original Message-----
From: Wendy McFarland [mailto:wmcfarla(_at_)nas(_dot_)edu]
Sent: 07 March 2003 11:40
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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


***************************************************************************
This communication (including any attachments) contains confidential 
information.  If you are not the intended recipient and you have received this 
communication in error, you should destroy it without copying, disclosing or 
otherwise using its contents.  Please notify the sender immediately of the 
error.

Internet communications are not necessarily secure and may be intercepted or 
changed after they are sent.  Abbey National Treasury Services plc does not 
accept liability for any loss you may suffer as a result of interception or any 
liability for such changes.  If you wish to confirm the origin or content of 
this communication, please contact the sender by using an alternative means of 
communication.

This communication does not create or modify any contract and, unless otherwise 
stated, is not intended to be contractually binding.

Abbey National Treasury Services plc. Registered Office:  Abbey National House, 
2 Triton Square, Regents Place, London NW1 3AN.  Registered in England under 
Company Registration Number: 2338548.  Regulated by the Financial Services 
Authority (FSA).
***************************************************************************


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



<Prev in Thread] Current Thread [Next in Thread>