Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 10th, 2003, 04:30 PM
Registered User
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting selected item in dropdown to match XML

Been working with a dropdown box that I want the selected default item to be whatever is in the XML for that record.

For example, if I have:


I want 'car' to be the value selected in my dropdown box. I have succesfully populated the dropdown box with all of the categories but cannot get the selected placement to work.

Anyone, help?!



Old December 11th, 2003, 05:56 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

Here is a solution but obviously I don't know the full xml source:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
      <head><title>Drop Down</title></head>
        <select id="lstCategories">
          <xsl:apply-templates select="root/categories/cat"/>
  <xsl:template match="categories/cat">
  <xsl:variable name="currentValue" select="text()"/>
  <option value="{$currentValue}">
    <xsl:if test="//record/nameCat[ . = $currentValue]">
      <xsl:attribute name="selected">selected</xsl:attribute>
    <xsl:value-of select="$currentValue"/>
Joe (MVP - xml)

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get selected item from listview? try.test.abc C# 1 January 4th, 2007 02:34 AM
selected item in dropdown not saved on postback rathbird ADO.NET 3 March 6th, 2006 08:44 AM
How Refer to Selected Item in DataGrid Morfoman General .NET 0 September 20th, 2005 11:41 AM
Datagrid - Scroll to selected item rodmcleay ASP.NET 1.0 and 1.1 Professional 2 February 21st, 2005 08:36 PM
How to get selected Item from Listbox? Iceman571 ADO.NET 1 March 25th, 2004 06:33 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.