Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping from 1 to x

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
Hi all,

I thought that this was going to be easy, but as with everything I try with XSLT I can't find a way of doing this.

I want to be able to provide a drop down list of years from 1950 to the current year. I thought i'd be able to do a loop from one attribute to another one, but i can't seem to find the correct syntax, or find anything on here.

Does anyone have an idea of how to do this?
Does anyone know of a good example site for learning xslt?

TIA

Tony
 
You can use recursion:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="/">
    <html>
      <head>
        <title>Test</title>
      </head>
      <body>
        <select name="year">
          <xsl:call-template name="years">
            <xsl:with-param name="year" select="1950"/>
          </xsl:call-template>
        </select>
      </body>
    </html>
  </xsl:template>
  <xsl:template name="years">
    <xsl:param name="year"/>
    <option value="{$year}">
      <xsl:value-of select="$year"/>
    </option>
    <xsl:if test="$year &lt; 2005">
      <xsl:call-template name="years">
        <xsl:with-param name="year" select="$year + 1"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top