Results 1 to 3 of 3

Thread: XSLT Loop?

  1. #1
    Join Date
    May 2003

    Question XSLT Loop?

    I have the following JavaScript loop within an old ASP page that loops through the years from a starting year variable (1900) to the ending year variable (1990):
    //Year array
    var strCurrDate = new Date();
    strCurrYear = strCurrDate.getYear();
    strVotingYear = strCurrYear - 18;//youngest voter year
    strDiffYear = strVotingYear - 1900;//years from youngest minus oldest voters
    //Voter year loop
    var LoopNumber = strDiffYear;
    for (i=1900;i<=strVotingYear;i++){
    	Response.Write(i + "<br />");//test
    	Response.Write("<option value='" + i + "'>" + i + "</option>");//test
    I'm wondering if I can do the same thing within XSLT with the use of a for:each method. I've been able to create the same variables with XSLT math, like this:
    <xsl:param name="current_year" select="''" />
    <xsl:param name="voting_year" select="$current_year - 18" /><!-- youngest voter year -->
    <xsl:param name="diff_year" select="$voting_year - 1900" /><!-- years from youngest minus oldest voters -->
    And maybe the XSLT code could look like this?
    <select id="year" name="selectYear">
    								<option value="" selected="">- Year -</option>
    	<xsl:for-each select="">
    		<!-- ???Not sure what to do here??? -->
    		<option value="???"><xsl:value-of select="???" /></option>
    Any help would be appreciated. Thanks.
    It's the end of the world as we know it...and I feel fine

  2. #2
    Join Date
    May 2008
    xsl:for-each is used for iteration over nodes, not over numeric ranges. Simply put, stick with the server-side generated way. There isn't really any use for such a thing in XSLT. After all, it only transforms markup; it doesn't generate data.

  3. #3
    Join Date
    May 2003
    That makes sense. So I'm now wondering if there's a way to use that code in a CDATA script within the XSLT doc. For instance, I have the following XSLT code that uses script that redirects the user when they make a selection from a jump-menu:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xslutput method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
    if (restore) selObj.selectedIndex=0;
    <select id="bycategory" name="selectCategory" onChange="MM_jumpMenu('parent',this,0)">
    <option value="" selected="true">- Select a Category -</option>
    <xsl:for-each select="categories/category">
    <option value="{link}">
    <xsl:value-of select="title" />

    Would there be a way to use my already-existing script in this way? If so, could you please point me in the right direction? Thanks.
    It's the end of the world as we know it...and I feel fine

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center