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 October 30th, 2007, 09:43 PM
Registered User
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Populating a Select Control from an XSL:Variable

I want to create and HTML <SELECT> control from an XSL:VARIABLE.

I have several of the same drop down in my html and want to leverage the XSL:variable to represent the options available. These options remain constant and I als need to select the option matching the value from the xml document I'm processing.

I haven't found anything to do this yet.

Something like...

<xsl:variable name="ddlOptions">
  <option>
    <value>days</value>
    <displayValue>day(s)</displayValue>
  </option>
  <option>
    <value>months</value>
    <displayValue>month(s)</displayValue>
  </option>
  <option>
    <value>years</value>
    <displayValue>year(s)</displayValue>
  </option>
</xsl:variable>


Now I need to loop thru this variable building the options for a select and select the correct option based on a value from my xml.

Sorry for the vagueness, but I can't find any real help out there.


 
Old October 31st, 2007, 04:21 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I'm assuming you are using XSLT 2.0.

If you create a variable containing your 'selected' value:

<xsl:variable name="selectedOption" select="/mydata/value" />

<select>
<xsl:for-each select="$ddlOptions/option">

  <option value="{value}">
  <xsl:if test="string(value) = $selectedOption">
    <xsl:attribute name="selected" select="selected"/>
  </xsl:if>
    <xsl:value-of select="displayValue"/>
  </option>
</xsl:for-each>
</select>

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing javascript variable in xsl:value-of select eruditionist XSLT 2 September 19th, 2008 05:23 PM
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
session variable not populating ph0neman Classic ASP Basics 8 March 13th, 2008 04:41 PM
XSL:Variable SELECT=sum(condictions) andreracco XSLT 3 August 15th, 2007 08:51 AM
<xsl:for-each> with a variable select="attribute" BeneathClouds XSLT 1 August 1st, 2005 03:36 AM





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