Solved

Dynamically creating selectbox in XSL

Posted on 2002-04-23
4
284 Views
Last Modified: 2012-06-22
Maybe someone can help me w/ this problem.

I'm trying to dynamically create a year selectbox in XSL. What I'd like to do is specify a start year and an end year and use a template to create the selectbox. Right now, everything is hardcoded.

Thanks in advance.
0
Comment
Question by:hobster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:jerelw
ID: 6964064
Have your code generate XML with a list of valid years, then simply generate you select

<Response>
  <YearList>
    <ValidYear>2000</ValidYear>
    <ValidYear>2001</ValidYear>
    <ValidYear>2002</ValidYear>
    <ValidYear>2003</ValidYear>
  </YearList>
</Response>

<select>
  <xsl:for-each select="Response/YearList/ValidYear">
    <option value="{ValidYear}"><xsl:value-of select="ValidYear"></option>
  </xsl:for-each>
</select>
0
 
LVL 2

Author Comment

by:hobster
ID: 6964076
That's something I want to avoid. Ideally, I just want to specify a start and end year and have xsl increment through each year to create the select box but I haven't found a way to do a Do While or For control type statement.
0
 
LVL 3

Expert Comment

by:jerelw
ID: 6965567
I hope you find a way to do i++ computations in xsl.

I tried unsuccessfully to increment that way, so I ended up having my code generate my content and have the xsl merely provide the presentation.

...I'm thinking, a [[CDATA block with JavaScript might do the trick, but I've never tried using Javascript to create my selects.

function createSelect(form, start, stop) {
  //create a select from start to stop.
}

Good luck!
0
 
LVL 6

Accepted Solution

by:
Wayne Bradney earned 100 total points
ID: 6966212
hobster,

For this kind of looping you'd need to resort to recursion. Something like:

<Response>
     <StartYear>1999</StartYear>
     <EndYear>2004</EndYear>
</Response>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <HTML>
      <BODY>
        <FORM>
          <SELECT>
            <xsl:call-template name="_build_select">
              <xsl:with-param name="start">
                <xsl:value-of select="/Response/StartYear"/>
              </xsl:with-param>
              <xsl:with-param name="end">
                <xsl:value-of select="/Response/EndYear"/>
              </xsl:with-param>
            </xsl:call-template>
          </SELECT>
        </FORM>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template name="_build_select">
    <xsl:param name="start"/>
    <xsl:param name="end"/>

    <OPTION>
      <xsl:attribute name="value">
        <xsl:value-of select="$start"/>
      </xsl:attribute>
      <xsl:value-of select="$start"/>
    </OPTION>

    <xsl:if test="$start != $end">
      <xsl:variable name="new_start">
        <xsl:value-of select="$start + 1"/>
      </xsl:variable>
      <xsl:call-template name="_build_select">
        <xsl:with-param name="start">
          <xsl:value-of select="$new_start"/>
        </xsl:with-param>
        <xsl:with-param name="end">
          <xsl:value-of select="$end"/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

Regards,
WMB
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question