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

Making a Table of Alphabetized Strings grouped by Firs

Subject: Making a Table of Alphabetized Strings grouped by First Letter
From: Elizabeth Barham <soggytrousers@xxxxxxxxx>
Date: 31 Jan 2002 05:21:06 -0600
alphabetized table html
Hi,

I'm a newbie so please be patient! :-)

I just looked at:
http://www.dpawson.co.uk/xsl/sect2/N7450.html

for clues as how to deal with this, but none of the examples seemed to
address this topic directly as they dealt with numerical values (that
is, it's number in the list) as opposed to their first letter value.

I currently have, as a key, all the counties in the State of Texas.
My goal is to have them look something like this:

    A		    B		    C
Anderson	Bailey		Caldwell
Andrews		Bandera		Calhoun
Angelina	Bastrop		Callahan
Aransas		Baylor		Cameron
Archer		Bee		Camp
Armstrong	Bell		Carson
		Bexar		Cass
		Blanco	

etc.


<xsl:for-each
	select="/projects/project/program-information/counties-served/county[generate-id(.)=generate-id(key('counties', @fips)[1])]">
  <xsl:sort/>

Where fips is a numerical identifier of the county. I am able to make
a listing well enough and because of the dpawson page mentioned above
I am able to do it better than before when it comes to their numerical
value.

While I can sort of see grabbing all the county names whose first
initial is different than the preceding, and then grabbing all those
whose first initial is the same, what is also troubling me is how
should I go about ending the table row (such as with 'C') when I do
not know if there is a county for every letter, for instance (while I
suppose I could check, it seems best to let it figure it out itself).

<xsl:for-each
	select="/projects/project/program-information/counties-served/county[generate-id(.)=generate-id(key('counties', @fips)[1])]">
  <xsl:sort/>

   <!-- this gives me a unique county iteration -->

   <xsl:if select="substring(., 1, 1) != substring(preceding::county, 1, 1)">
     <td>
       <table>
         <xsl:variable name="letter">
 	    <xsl:value-of select="substring(.,1,1)" />
          </xsl:variable>
        <tr><th><xsl:value-of select="$letter"/></th></tr>
         <xsl:for-each select=".|following-sibling::county[substring(.,1,1) = $letter]">
           <tr><td><xsl:value-of select="."/></td></tr>
         </xsl:for-each>
        </table>
     </td>
   </xsl>
</xsl:for-each>

While this *might* produce a individual table within a td element, how
do we know when to end the tr? Perhaps if we could determine the
number of letters the strings begin with in advance?

Thank you,
Elizabeth



     
      

 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.