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

Alphabetic Sort with Letter Headers (again)

Subject: Alphabetic Sort with Letter Headers (again)
From: D Laurie <dlaurie@xxxxxxxxxxx>
Date: Mon, 1 Nov 2004 11:35:22 -0700 (MST)
letter headers
Hello XSL list,

I tried to send this last week but somehow my webmail converted all of my html and xml code snippet into web display text.

Apparently I need help with my help :).

I have been trying to sort and display a a set of elements alphabetically and grab the first letter for a group header. The

header would only appear once and won't appear if there is an empty set (eg. 'X'). For example I want to transform something

like:

<content>
<element>Bob</element>
<element>Craig</element>
<element>Al</element>
<element>Frank</element>
<element>Bill</element>
<element>Barb</element>
<element>Andrew</element>
<element>Felix</element>
<element>Farah</element>
</content>

into:

A
Andrew
Al

B
Barb
Bill
Bob

C
Craig

F
Farah
Felix
Frank

The xml I am using is not flat, ie. there are elements being sorted that are 'cousins' of one another, not just siblings. The

xsl I have written so far gets the sort OK and strips off the first letter but does so for each element sorted.

I have tried to test the pulled letter against that of the following-sibling but the sort interferes with that. I have also

tried to create a variable for the letter at the next position() but that didn't work either.

The xsl I use:

<xsl:template match="body" mode="alpha-title">
<xsl:for-each select="part/chapters/mapunits/maps">
<xsl:sort select="maptitle"/>
<xsl:variable name="maptitle" select="maptitle"/>
<xsl:variable name="firstletter" select="substring($maptitle,1,1)"/>
<div class="trackNumber">
<xsl:value-of select="$firstletter"/>
</div>
<div class="mapTitle">
<a href="../../Maps/{../../@chap}/{../@mapunitNumber}/{@mapNumber}/Normal/">
<xsl:value-of select="maptitle"/>
</a>
</div>
</xsl:for-each>
</xsl:template>



A relevant snippet of xml schema:


<body>
       <part>
            <chapters>
                 <mapunits>
                      <maptitle/>
                      <maps/>
                 </mapunits>
            </chapters>
        </part>
</body>

I am pulling all the maptitles and maps from all of the parts.

Has anyone tried something like this before?

Thanks for your time,

Dave
PS. I have tried again sending through pine.

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.