How to populate dropdown with numbered values like years

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 &lt; $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:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: