[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Creating a html <select> dropdown menu in XSL, whe

Subject: Re: Creating a html <select> dropdown menu in XSL, where the attribute of an XML element is the selected value when page loads
From: Martin Jackson <martsonjackin@xxxxxxxxx>
Date: Tue, 12 Jan 2010 22:09:24 +0100
Re:  Creating a html <select> dropdown menu in XSL
The problem is now solved, thanks to you all and some code I found by
googling, which I modified to suit my needs,

For the months, Kens question, "why do you need an algorithmic
approach?" made me realize I didn't. Instead I just made 12 static
<choose> parts, one for each month. Like this:

<xsl:template match="@month">
	<xsl:variable name="month">
		<xsl:value-of select="."/>
	</xsl:variable>
	
		<xsl:choose>
			<xsl:when test="$month='januari'">
				<option value="januari" selected="selected">
					januari
				</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="januari">
					januari
				</option>
			</xsl:otherwise>
		</xsl:choose>

<!-- and so on -->
</xsl:template>

The solution for the days and years was indeed to use recursive template calls.

The code for this is found below, if anybody happens upon this thread
and is interested in how I solved it.


Best regards,
Martin Jackson



<xsl:template match="@day">

	<xsl:variable name="day">
		<xsl:value-of select="."/>
	</xsl:variable>
	
	<xsl:call-template name="incrementValue">
		<xsl:with-param name="value">1</xsl:with-param>
		<xsl:with-param name="invar" select="$day"></xsl:with-param>
		<xsl:with-param name="stop">31</xsl:with-param>
	</xsl:call-template>
	
</xsl:template>

<!-- and another template just like it for the years, but with the
parameters "value" and "stop" changed from 1 and 31 to 1900 and 2010.
Plus this: -->

<xsl:template name="incrementValue">
	<xsl:param name="value"/>
	<xsl:param name="invar"/>
	<xsl:param name="stop"/>
	<xsl:if test="$value &lt;= $stop">

		<xsl:choose>
			<xsl:when test="$value=$invar">
				<option value="{$value}" selected="selected">
					<xsl:value-of select="$value"/>
				</option>
			</xsl:when>
			<xsl:otherwise>
				<option value="{$value}">
					<xsl:value-of select="$value"/>
				</option>
			</xsl:otherwise>
		</xsl:choose>	
		<xsl:call-template name="incrementValue">
			<xsl:with-param name="value" select="$value + 1"/>
			<xsl:with-param name="invar" select="$invar"></xsl:with-param>
			<xsl:with-param name="stop" select="$stop"></xsl:with-param>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.