aspose file tools*
The moose likes XML and Related Technologies and the fly likes Default selection of value in dropdown box in xsl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Default selection of value in dropdown box in xsl" Watch "Default selection of value in dropdown box in xsl" New topic
Author

Default selection of value in dropdown box in xsl

sushi sri
Ranch Hand

Joined: Oct 27, 2009
Posts: 38
Hi,

I'm new to xsl and working in an xsl implemntation project.
I've show default selection to one of the value in the drop down. My current dropdown display is like this.

<select name="fundslist">
<option value="" selected="Y">Select portfolio From</option>
<xsl:for-each select="/ROWSET/portfolio">
<option>
<xsl:attribute name="value">
<xsl:value-of select="portfolicode"/>
</xsl:attribute>
<xsl:value-of select="portfoliodesc"/><xsl:text> </xsl:text></option>
</xsl:for-each>
</select>

I'm getting all my values in an xml to this xsl.
The default selection is set to select option.
Now i've to change the selection to the value i get in my xsl which is
<xsl:value-of select=""/ROWSET/defaultporfoliocode" />

How can i compare this value to the protfoliocode value in the dropdown and make that option as highlighted/selected by default.
If any code in this regard i get, it's highly appreciated
Please, let me know how can i do this.

Thanks
uranch
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

You don't compare anything to anything in the dropdown, because you are generating the dropdown. You compare something else to something somewhere else (presumably these things come from outside the code you posted).

The usual strategy in XSLT is this:

(1) Decide what HTML you want to produce.

(2) Write XSLT which produces that HTML.

In this case I suspect it's a "selected" attribute which you want to conditionally generate, or something a lot like that. You already know how to produce an attribute, I see from your posted code. To do it conditionally you would use an <xsl:if> element.
sushi sri
Ranch Hand

Joined: Oct 27, 2009
Posts: 38
HI,

I need the code for this. Can any body send me.

Thanks
sushi sri
Ranch Hand

Joined: Oct 27, 2009
Posts: 38
i think i've to write some thing like this. Please, correct me, how to make this work.
<select name="fundslist">
<xsl:for-each select="/ROWSET/portfolio">
<option>
<xsl:if test="portfolicode=/ROWSET/defaultportfolio">
<xsl:attribute name="selected">1</xsl:attribute>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="portfolicode"/>
</xsl:attribute>
<xsl:value-of select="portfoliodesc"/><xsl:text> </xsl:text></option>
</xsl:for-each>
</select>

thanks

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default selection of value in dropdown box in xsl
 
Similar Threads
Passing parameters in XSL to JavaScript
Not getting my variable value
Remove unwanted space before and after the table using javascript
Help on XSL XPath
Passing parameters in XSL to JavaScript