This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Making a Table of Alphabetized Strings grouped by First Letter
- From: Elizabeth Barham <soggytrousers at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: 31 Jan 2002 05:21:06 -0600
- Subject: [xsl] Making a Table of Alphabetized Strings grouped by First Letter
- Reply-to: xsl-list at lists dot mulberrytech dot com
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