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:
  #1  
Old March 4th, 2004, 12:03 AM
peasfood peasfood is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Boston
Posts: 26 peasfood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Display selected value in XSL combo

Hi there,

Here is a XSL combo that I use in my app.

<select name="Year" value='{//Time/@Year}'>
<option >1900</option>
<option >1901</option>
<option >1902</option>
<option >1903</option>
<option >1904</option>
<option >1905</option>
</select>

How can I capture the value selected in this combo ?
Help please ?

thanks in advance.

Reply With Quote
  #2  
Old March 4th, 2004, 11:41 AM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
Where do you want to capture the value from the combo?
On the server side or the client side?
What client scripting technology or server side language would be using?

Reply With Quote
  #3  
Old March 4th, 2004, 11:23 PM
peasfood peasfood is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Boston
Posts: 26 peasfood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is to capture it in XSL itself.
Actually "//Time/Year" attribute captures the value.

Here too, its the same, but I want the selected value to be highlighted when I visit the page time.

What happens currently is that the page is reset & the combo always shows 1900(even as (//Time/Year holds 1905 as the value inside the DB).

Basically, I want to know some XSL attribute like <xsl:valueof select ... > which will highlight the selected value when I visit the web page again.

Hope am clear.

thanks.

Reply With Quote
  #4  
Old March 5th, 2004, 07:53 AM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
If the 19xx values are going to be hardcoded in the XSL:
Code:
<xsl:variable name="dropdownHtml">
	<select name="Year">
		<option>1900</option>
		<option>1901</option>
		<option>1902</option>
		<option>1903</option>
		<option>1904</option>
		<option>1905</option>
	</select>
</xsl:variable>

<xsl:variable name="searchFor">
	<xsl:text>></xsl:text><xsl:value-of select="//Time/@Year"/>
</xsl:variable>

<xsl:value-of disable-output-escaping="yes" select="substring-before($dropdownHtml, $searchFor)"/>
<xsl:text> selected="selected"></xsl:text><xsl:value-of select="//Time/@Year"/>
<xsl:value-of disable-output-escaping="yes" select="substring-after($dropdownHtml, $searchFor)"/>


If the 19xx values come from the XML:
Code:
<select name="Year">
<xsl:for-each select="/child::node()/years/year">
	<xsl:choose>
		<xsl:when test=". = //Time/@Year">
			<option selected="selected"><xsl:value-of select="."/></option>
		</xsl:when>
		<xsl:otherwise>
			<option><xsl:value-of select="."/></option>
		</xsl:otherwise>
	</xsl:choose>
</xsl:for-each>
</select>


OR if the values come from a document called years.xml in the same dir as the XSL (the best solution):
Code:
<select name="Year">
<xsl:for-each select="document(years.xml)/years/year">
	<xsl:choose>
		<xsl:when test=". = //Time/@Year">
			<option selected="selected"><xsl:value-of select="."/></option>
		</xsl:when>
		<xsl:otherwise>
			<option><xsl:value-of select="."/></option>
		</xsl:otherwise>
	</xsl:choose>
</xsl:for-each>
</select>


On a side note, for performance sake, it is not always wise to use // in your XPath unless you absolutely need it. // means descendent or self which is slower then saying something like /rootElementName/Time/@Year or /child:node()/Time/@Year. You might want to read up on your XPath.

I would also be wide to put this functionality into a template and put the template in an imported XSL file.

Matt

Reply With Quote
  #5  
Old March 7th, 2004, 11:31 PM
peasfood peasfood is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Boston
Posts: 26 peasfood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks Matt for the detailed reply.
My values are indeed hardcoded in the XSL.

There are two modes of accessing this web page.

CREATE: In this mode,the combo will be always showing 1900. I have no problem with this.

EDIT: This is where I have a problem. The combo still shows 1900 , even as \\Project\FeeType contains 1905 or some other selected value.

I want the combo to highlight the selected value with the rest of the values also as part of the combo.

I tied the foll , but didnt succeed.


*** Code ***
<select name="Year">

<xsl:choose>
<xsl:when Year ="@Year='1900' or @Year='1901' or @Year='1902' " >

<xsl:if test="@Year='1900'">
<option value="1900" selected="selected">1900</option>
<option value="1901">1901</option>
Rest of the ...values
</xsl:if>

<xsl:if test="@Year='1901'">
<option value="1900" >1900</option>
<option value="1901" selected="selected">1901</option>
Rest of the ...values
</xsl:if>

Similarly , this continues till 1905.

</xsl:when>

The Otherwise clause is for CREATE mode.
<xsltherwise>

<option >1900</option>
<option >1901</option>
<option >1902</option>
<option >1903</option>
<option >1904</option>
<option >1905</option>


</xsltherwise>
</xsl:choose>

Thanks again for all your patience.

Reply With Quote
  #6  
Old March 8th, 2004, 07:11 AM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
Use the code I gave and an editor like ActiveState's Komodo so that you can set breakpoints and change the code as needed. Don't use the *** Code *** part of your last reply. Use one of the three solutions I gave you or you programmer friends will laugh at you at this years summer BBQ. Trust me.

http://www.activestate.com

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Display selected value in XSL combo


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 2 hosted by Hostway
Stay green...Green IT