• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Default selection of value in dropdown box in xsl

 
sushi sri
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

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

Thanks
 
sushi sri
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic