[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] glossary sorting/indexing question


Subject: Re: [xsl] glossary sorting/indexing question
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 20 May 2008 13:02:20 +0100

> <!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "&#160;">]>
personally I wouldn't bother, #160 isn't any harder to type than nbsp,
and having the doctype there can cause problems with some systems, which
use it as a hint to request stylesheet validation, thus generating an
error on every element as this dtd doesn't define any elements.



<!-- subhead key -->
<xsl:key name="subhead" match="/document/section"
use="translate(substring(./title,1,1),$lochars,$upchars)" />


This is an XSLT2 feature, XSLT 1.0 does not allow variables in key
definitions. If you are using xslt2 though it's simpler to get rid of
the variables and use

<!-- subhead key -->
<xsl:key name="subhead" match="/document/section"
         use="upper-case(substring(title,1,1))" />

(you never need to start an xpath with ./)

similarly of course you can use upper-case in the key() function, but...

> count(. |
> key('subhead',translate(substring(./title,1,1),$lochars,$upchars))[1])

This is muenchian grouping, and is much more simply expressed in xslt2 using

<xsl:for-each-group select="/document/section"
group-by="upper-case(substring(title,1,1))">

then to access the members of the group, replace
"key('subhead',$initial) by current-group()

so... I think your stylesheet would be fine as an example of muenchian
grouping in xslt 1 if you made the key definition legal by getting rid
of the variable references:

<xsl:key name="subhead" match="/document/section"
use="translate(substring(./title,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ)" />


but in xslt2 such idiomatic uses of muenchian grouping can more or less
automatically be converted to xsl:for-each-group, which probably doesn't
make much difference to the way the generated code runs, but makes it
rather more readable.


David


________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________


Current Thread
Keywords