Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Alphabetic sort retaining first letters as Headers

From: David Laurie <dlaurie@----------->
To:
Date: 11/1/2004 6:39:00 PM
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

David Laurie
MA Humanities Computing


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent