|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Creating index headers
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@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Manne
> Miettinen
> Sent: 29 January 2002 08:50
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: 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@xxxxxx
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








