This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Creating index headers
- From: "Michael Kay" <michael dot h dot kay at ntlworld dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 29 Jan 2002 09:28:26 -0000
- Subject: RE: [xsl] Creating index headers
- Reply-to: xsl-list at lists dot mulberrytech dot com
This is a grouping problem, where the grouping key is the first character of
the value. For XSLT 1.0, use Muenchian grouping as described in
http://www.jenitennison.com/xslt/grouping, using substring(.,1,1) to compute
the grouping key.
With XSLT 2.0 you can write:
<xsl:for-each-group select="entry" group-by="substring(term, 1, 1)">
<xsl:sort select="substring(term, 1, 1)"/>
<h2><xsl:value-of select="substring(term, 1, 1)"/></h2>
<a name="{substring(term, 1, 1)"/>
<xsl:apply-templates select="current-group()"/>
</xsl:for-each-group>
This should work with Saxon 7.0.
Mike Kay
> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Manne
> Miettinen
> Sent: 29 January 2002 08:50
> To: xsl-list@lists.mulberrytech.com
> Subject: [xsl] Creating index headers
>
>
> Hi there,
>
> I have a glossary of scientific terms in xml that contains
> entries like this:
>
> <entry type='n'>
> <term>A term</term>
> <treq>Finnish translation equivalen</treq>
> <def>Definition(s) of the term</def>
> ... some other fields omitted
> </entry>
>
> I would like to create html-version of the glossary where all
> the entries would
> be sorted alphabetically using the content of term-element as
> sort key. For each
> new beginning letter I would like to produce a header and
> anchor like this:
>
> <h2>A</h2>
> <a name=a"/>
>
> <dl>
> <dt type="term">A term</dt>
> <dt type="treq">Finnish translation equivalent</dt>
> <dd>Definitions of the term</dd>
>
> <h2>B</h2>
> ...
>
> My first cut at the problem was creating a variable for each
> letter in the
> alphabet, like this
>
> <xsl:variable name="a"
> select="/glossary/entry[substring(term,1,1)='a']|entry[substri
> ng(term, 1,1)='A']"/>
> <xsl:variable name="b"
> select="/glossary/entry[substring(term,1,1)='b']|entry[substri
> ng(term, 1,1)='B']"/>
>
> However the glossary contains also numbers and symbols (, +,
> α, β etc
> that I would like to lump under a common heading of "Numbers
> and symbols".
>
> Any suggestions?
>
> --
> Manne MIETTINEN manne.miettinen@csc.fi
> CSC - Scientific Computing Ltd. +358 9 457 2517 (Tel)
> PO BOX 405 +358 50 381 9510 (GSM)
> FIN 02101 Espoo, FINLAND +358 9 457 2302 (Fax)
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list