XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 4th, 2002, 11:50 AM
aivarannamaa aivarannamaa is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 1 aivarannamaa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How to do HTML selects with xslt?

Lets say I'm going to have a form with a select with 12 options, option values being the numbers ov months and option labels being names of months.

I have a xml document saying (among other things) which option should be selected.

Beforementioned form and notably select are to be constructed with a xsl stylesheet.

One solution would be like this:
Code:
...
<select>

<xsl:element name="option">
  <xsl:attribute name="value">1</xsl:attribute>
  <xsl:if test="month = 1">
     <xsl:attribute name="selected">selected</xsl:attribute>
  </xsl:if>
  January
</xsl:element>

<xsl:element name="option">
  <xsl:attribute name="value">2</xsl:attribute>
  <xsl:if test="month = 2">
     <xsl:attribute name="selected">selected</xsl:attribute>
  </xsl:if>
  February
</xsl:element>

...(and so on)


ie. too much typing
Do you know a better way to solve this?

Reply With Quote
  #2  
Old September 4th, 2002, 11:25 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
i would probably use a looping construct there combined with a switch/case construct...
Code:
<!--  ====  THE SWITCH   ==== -->
<xsl:choose>
      <xsl:when test="first_condition_true">
              <!-- do this -->
      </xsl:when>
      <xsl:when test="second_cond_true">
              <!-- do this -->
       </xsl:when>
<!--  ....... -->
       <xsl:otherwise>
             <!--all tests failed.. do this -->
       </xsl:otherwise>
</xsl:choose>

<!--  ====  THE LOOP   ==== -->
<xsl:for-each select="element">
    <!--  do something -->
</xsl:for-each>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > How to do HTML selects with xslt?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway