[xsl] Previous/Next element

Subject: [xsl] Previous/Next element
From: James Cummings <James.Cummings@xxxxxxxxx>
Date: Wed, 9 Jul 2003 23:03:33 +0100 (BST)
Ok, I know this is a FAQ.... but I want to have a link to the previous sibling and another to
the following sibling.

<Day code="6000">
<Day code="6010">
<Week code="8012">
<Day code="3200">

<xsl:template match="Day | Week">
<div class="{name()}" id="{concat($ms, '.',@code)}">
<xsl:if test="preceding-sibling::*/@code">
<span class="prev"> <a href="{concat('#', $ms, '.', preceding-sibling::*/@code)}">Prev</a>
</span><xsl:text>  </xsl:text> </xsl:if>
<xsl:if test="following-sibling::*/@code">
<span class="next"> <a href="{concat('#', $ms, '.', following-sibling::*/@code)}">Next</a>
    <xsl:apply-templates />


So each Day or Week is turned into a <div> with an @id of blah.6000 based on its @code
and a global variable $ms.  The 'next' button following-sibling::*/@code seems to work
well, not minding whether it is Day or Week.  The 'Prev' button always goes back to
the first one.  I realise the usual way to do this is based on count() or position(),
but since I want to base it on the previous/following's Day/Week's @code, I wasn't
sure how to do this.


Dr James Cummings, James.Cummings@xxxxxxxxx, http://www.uea.ac.uk/~q503
Cursus Project, School of Music, University of East Anglia,
Norwich, Norfolk, NR4 7TJ, UK  Tel:(01603)593-595

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

Current Thread