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

RE: Selecting an option

Subject: RE: Selecting an option
From: Heather Lindsay <heather.lindsay@xxxxxxxxxxxxx>
Date: Wed, 12 Sep 2001 15:37:56 -0400
xml option value
hi,
	I'm not sure if this is what you are asking without more information
but here it goes...

Say you have an XML file that looks like this:

<myFile>
	<myValues>
		<value>1</value>
		<value>2</value>
		<value>3</value>
		<value>4</value>
		<value>5</value>
	</myValues>
	<defaultValue>5</defaultValue>
</myFile>

And you want an html like this:

<HTML>
<Body>
	<Table>
		<tr>
			<td>
				<select name="myMenu">
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5"
selected="selected">5</option>
				</select>
			</td>
		</tr>
	</Table>
</Body>
</HTML>

Then you would need this XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/">
	<html>
	   <body>
		<table>
		   <tr>
			<td>
			   <select name="myMenu">
				<xsl:apply-templates
select="myFile/myValues/value">
					<xsl:with-param name="default"
select="myFile/defaultValue"/>
				</xsl:apply-templates>
			   </select>
			</td>
		   </tr>
		</table>
	   </body>
	</html>
   </xsl:template>
	
   <xsl:template match="value">
	<xsl:param name="default"/>
	<xsl:choose>
	   <xsl:when test=". = $default">
		  <option value="{.}" selected="selected"><xsl:value-of
select="."/></option>
	   </xsl:when>
	   <xsl:otherwise>
		<option value="{.}"><xsl:value-of select="."/></option>
	   </xsl:otherwise>
	</xsl:choose>
   </xsl:template>

</xsl:stylesheet>

I hope that helps.  It's hard to know what you are asking for without
example XML and the relevant segment of what you've tried so far in your
XSLT.

Good luck,
Heather


-----Original Message-----
From: Carlos Durand Silvestrin [mailto:csilvestrin@xxxxxxxxxxx]
Sent: Wednesday, September 12, 2001 1:53 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Selecting an option


I want to know the better way to select one option below using XSLT:

<select name="note">	
	<option value="0">0</option>
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	<option value="6">6</option>
	<option value="7">7</option>
	<option value="8">8</option>
	<option value="9">9</option>
</select>

For example, select the 5th option when my node in XML has the same value
<option value="5" selected="selected">5</option>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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-2011 All Rights Reserved.