|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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>
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > How to do HTML selects with xslt? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|