RE: breaking sorted material into subsections

Subject: RE: breaking sorted material into subsections
From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 19 Sep 2000 17:44:16 +0200 (MET DST)
Hi Eric,

> This works quite nicely.  However, while I want a separate heading for each
> letter, I might also have some index entries that begin with numbers or
> symbols (@,#, etc.), in which case I'd really like to group all such items
> together under one heading.  I'm thinking I want something like:
> 
> <xsl:template match="pages">
>   <xsl:for-each select="//index[count(. | key('letters',
> substring(@entry,1,1))[1]) = 1]">
>     <xsl:sort select="@entry" />
>     <xsl:variable name="initial" select="substring(@entry,1,1)" />
>     <xsl:choose>
> 
>                <!--can't figure out what to do with following line -->
>       <xsl:when test="($initial = 'something to check if 1 or 2 or...')">

translate() would be a good guess I think ...
http://www.w3.org/TR/xpath#function-translate

<xsl:when test="translate($initial,'1234567890@#','')=''">

means: translate the given characters to '' (delete them) and leave all 
others as they are. (not tested ...)

>         <h2>Numbers or symbols</h2>
> 
>                <!--not sure if following 4 lines do what I want
>                    since I haven't been able to get here  -->
>         <xsl:apply-templates>
>           <xsl:sort select="@entry" />
>           <p><a href="{../@location}"><xsl:value-of
> select="@entry"/></a></p>
>         </xsl:apply-templates>

Hmm, don't know what you are trying to do, but you can't create literal
output elements inside of xsl:apply-templates.
Could it be that you don't need xsl:apply-templates at all here?

>       </xsl:when>
>       <xsl:otherwise>
>         <h2><xsl:value-of select="$initial" /></h2>
>         <xsl:for-each select="key('letters', $initial)">
>           <xsl:sort select="@entry" />
>           <p><a href="{../@location}"><xsl:value-of
> select="@entry"/></a></p>
>         </xsl:for-each>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:for-each>
> </xsl:template>
> 

Hope that helps,
Oliver


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@xxxxxxxxxxxxxxxxxxxxxxx             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread