Re: [xsl] access to preceding-sibling in a sorted list

Subject: Re: [xsl] access to preceding-sibling in a sorted list
From: "Simon Ruf" <simon@xxxxxxxxx>
Date: Tue, 4 Sep 2007 16:20:04 +0200
Thanks alot.
I haven't tried it yet but found quite some bit of information about
this grouping-thing and I think I'll be able to implement this - and
even better: I think this answers another not-yet-asked question I had
in mind.


On 9/4/07, David Carlisle <davidc@xxxxxxxxx> wrote:
> this is easier in xslt2 (where xsl-for-each-group does what you want) in
> xslt1 there are essentially two approaches.
> 1 (the "pipeline" approach) first sort the items, not adding the id
> attributes, but do it into a variable
>   <xsl:variable name="first-pass">
>     the code to generate a list of <li> elements
>   </xsl:variable>
> then use the xx:node-set() extension function taht most XSLT1 engines
> have to allow you to proxcess this, the sorted items now are siblins so
> you can do
>   <xsl:for-each select="xx:node-set($first-pass)/li">
>     <xsl:copy>
>       <xsl:if test="...."><xsl:attribute name="id".....
> 2 (the grouping approach)
> View it as a grouping problem, and use one of the XSLt 1 grouping idioms
> (google for muenchian grouping) for example You want to group on first
> letter, sort the groups, sort each item in each group and add an
> attribute on teh first
> <xsl:key name="l" match="card" use="substring(full-name,1,1)"/>
> <xsl:for-each
> select="card[generate-id()=generate-id(key('l',substring(full-name,1,1)))]">
>  <xsl:sort select="full-name"/>
> <xsl:variable name="letter" slect="key('l',substring(full-name,1,1)))"/>
> <xsl:for-each select="key('l',$letter)">
> <xsl:sort select="full-name"/>
> <li>
> <xsl:if test="position()=1"><xsl:attribute name="id"><xsl:value-of
> select="$letter/></xsl:attribute>
> <xsl:value-of select="full-name"/>
> (untested)
> 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