Muenchian methods easier with XSLT 2
In Vertical Site we have full support for XSLT 2.0. When you meet a grouping challenge you should look at some new functionality in the new spec. In this example we shall group an articlelist by the first letter.
The challenge
The list we are implementing lies at Helsebiblioteket.
Ok, what to do first. We check out the new grouping functions to see what it can do for us.
I start of easy and apply my way into /verticaldata/contents. I make sure I stand on the outside of contents. It can be a lot of content-nodes and I don't want to repeat myself.
<xsl:template match="contents">
<div id="jumpmenu">
<xsl:for-each-group group-by="substring(title, 1,1)" select="content">
<xsl:sort order="ascending" select="substring(title, 1,1)"/>
<a href="{$url}#{substring(title, 1,1)}"><xsl:value-of select="substring(title, 1,1)"/></a><xsl:text> </xsl:text>
</xsl:for-each-group>
</div>
<xsl:for-each-group group-by="substring(title, 1,1)" select="content">
<xsl:sort order="ascending" select="substring(title, 1,1)"/>
<xsl:apply-templates mode="title" select="."/>
<xsl:apply-templates select="current-group()"/>
</xsl:for-each-group>
</xsl:template>
The magic the is in the grouping. I group by the first letter of the title. That really solves my problem. Then I apply on contents, but first I print a grey bar listing the same letter as you can see on the webpage.
Smooth?




Comments
If you want to comment on this article you need to be logged in.