|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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? |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
||||
|
||||
|
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 |
|
#5
|
|||
|
|||
|
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. <xsl therwise> <option >1900</option> <option >1901</option> <option >1902</option> <option >1903</option> <option >1904</option> <option >1905</option> </xsl therwise></xsl:choose> Thanks again for all your patience. |
|
#6
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Display selected value in XSL combo |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|