Subject: RE: breaking sorted material into subsections From: Eric Taylor <Eric.Taylor@xxxxxxxxxxxx> Date: Tue, 19 Sep 2000 09:17:04 -0500 |
Thanks Oliver. That did the trick for me. Now I have another question. Since my XML was slightly different than Don's guess, after applying your response to my structure, I have this: <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)" /> <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:for-each> </xsl:template> 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...')"> <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> </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> except that I haven't found anything that works on the xsl:when line that generates any output at all (and yes, I did remember to alter my XML to make sure there was an index entry that began with a number) to see if what I constructed following works. Could someone help me out here, and also point me in the right direction if the rest of my solution is misguided. Thanks. Eric XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: breaking sorted material into s, Don Bruey | Thread | RE: breaking sorted material into s, Oliver Becker |
RE: Converting special characters, Kay Michael | Date | Re: count of element occurrences, Sebastian Rahtz |
Month |