Archive date links
This is an open discussion with 1 reply, filed under XSLT.
Search
You might want to try using more than one recursive template: one for years, one for months. It would look like this (including the format-number function to maintain the double digit month format):
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> <xsl:template match="/"> <xsl:call-template name="year-recursion"> <xsl:with-param name="dr-month" select="$this-month" /> <xsl:with-param name="dr-year" select="$this-year" /> </xsl:call-template> </xsl:template> <xsl:template name="year-recursion"> <xsl:param name="dr-year"/> <xsl:param name="dr-month"/> <xsl:if test="$dr-year > 2007"> <xsl:call-template name="month-recursion"> <xsl:with-param name="dr-month" select="$dr-month" /> <xsl:with-param name="dr-year" select="$dr-year" /> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="month-recursion"> <xsl:param name="dr-year"/> <xsl:param name="dr-month"/> <li><xsl:value-of select="$dr-year" />-<xsl:value-of select="format-number($dr-month, '00')" /></li> <xsl:choose> <xsl:when test="$dr-month > 1"> <xsl:call-template name="month-recursion"> <xsl:with-param name="dr-year" select="$dr-year" /> <xsl:with-param name="dr-month" select="$dr-month - 1" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="year-recursion"> <xsl:with-param name="dr-year" select="$dr-year - 1" /> <xsl:with-param name="dr-month" select="12" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Create an account or sign in to comment.
Hi all,
I'm trying to create a list of date links on my archive page between a certain date and either $this-month or ideally the month of the most recent blog post. For example the list might look something like this:
etc... I'm not sure what the best way of achieving this is. I've tried using recursion to output the numbers which I could then convert to text based dates, but I keep running into xslt errors.
This is what I have tried: