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

Creating a html <select> dropdown menu in XSL, where t

Subject: 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: Thu, 17 Dec 2009 17:59:23 +0100
 Creating a html <select> dropdown menu in XSL
Hi all,

I'm trying to make a page where I can edit the data (like name and
date of birth) of a person in a data base.

I have a php page which gets the data for the person you have chosen
to edit from the data base and generates an XML element that looks
like this:

<PERSON ID='$id' FIRSTNAME='$firstname' LASTNAME='$lastname'
DAY='$day' MONTH='$month' YEAR='year'></PERSON>

I want to use XSL to generate a html page, that have three dropdown
menus for Day, Month and Year. I want them to display the correct data
from the data base when the page loads.

For example, if someone is born on the 3rd, I want the Day dropdown
menu, which consists of numbers 1-31 to display "3"

In html this is done by giving one of the <option> elements in the
<select> menu the attribute "SELECTED", like this:

  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3" SELECTED>3</option>
  <option value="4">4</option>



Earlier, I didn't use XSL and instead just generatead html directly in
my php document. Then the code below did the trick. What would the xsl
equivalent look like?

for($current_day=1; $current_day <= 31; $current_day++)
echo "<option value='$current_day'";
echo " SELECTED";
echo ">$current_day</option>";

How can this be done in XSL? As far as I understand, the existing loop
functions in XSL, like <xsl:for-each> are used to loop over a number
of elements? I , on the other hand, want to output a number of html
<option> elements, where the value increments for each iteration, and
compare them all to the same attribute of a certain XML <person>
element, and (when I get a match) output the html <option> element
with "SELECTED" added.

Martin Jackson

Current Thread


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.
First Name
Last Name
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.