How to populate dropdown with numbered values like years
April 28, 2009 Leave a comment
Dude,.. I was playing arund with some xsl and was wondering how can you populate a dropdown menu with xsl,.. well it is no biggy,. this is how i did it ,..
first we have to calculate the number span lets say from this year to 50 years back ,.. with a recurcive template. Something like this:
<xsl:template name="yearList">
<xsl:param name="year" />
<xsl:variable name="lastYear" select="sc:year() - 50" />
<option><xsl:value-of select="$year"/></option>
<xsl:if test="$lastYear < $year"><br />
<xsl:call-template name="yearList"><br />
<xsl:with-param name="year" select="$year - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
now we have to call the template with initial parameters.
<select>
<xsl:call-template name="yearList">
<xsl:with-param name="year">2009</xsl:with-param>
</xsl:call-template>
</select>
thats it ,.. (c: