Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using XSL to mark an item as 'selected' in a select list

Status
Not open for further replies.

Baldyal

Programmer
Dec 6, 2002
1
US
I am fairly new to xml and xsl, but I am having difficulty showing an item as selected in a select list after it has been populated. I can't seem to change the option value based on a variable. Here is my simpe code:

<select name=&quot;yr&quot;>
<xsl:for-each select=&quot;selections/taxyear/year&quot;>
<option>
<xsl:value-of select=&quot;text()&quot;/>
</option>
</xsl:for-each>
</select>
Thanks
 
<xsl:variable name=&quot;selectedoption&quot;>February</xsl:variable>


<select name=&quot;yr&quot;>
<xsl:for-each select=&quot;selections/taxyear/year&quot;>
<option>

<xsl:value-of select=&quot;text()&quot;/>

<xsl:if test=&quot;text=$selectedoption&quot;>
<xsl:attribute name=&quot;SELECTED&quot;/>
</xsl:if>

</option>
</xsl:for-each>
</select>

This should select the appropriate list item if the text matches that of the 'selectedoption' variable.

Hope this is what you were after!

Nick (Software Developer)


nick@retrographics.fsnet.co.uk
nick.price@myenable.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top