how to get the Select box - Option Selected
This is an open discussion with 6 replies, filed under General.
Search
an xsl:if statement would work.
Something like
<xsl:if test="/path/to/value = option-value">
<xsl:attribute name="selected">selected</xsl:attribute>
</xsl:if>
A bit tedious if each option is hand coded as this will need to go inside each option tag, but works best if in a foreach statement.
If you've got static values you can actually loop over them by using the tokenize
function which explodes a string into a nodeset:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:str="http://exslt.org/strings" extension-element-prefixes="exsl str"> <xsl:template match="/"> <select name="fields[dmonth]"> <xsl:for-each select="str:tokenize('Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec',',')"> <option> <xsl:if test="/path/to/value = text()"> <xsl:attribute name="selected">selected</xsl:attribute> </xsl:if> <xsl:value-of select="text()"/> </option> </xsl:for-each> </select> </xsl:template> </xsl:stylesheet>
Good solution there Nick. I love the Tokenize.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:str="http://exslt.org/strings" xmlns:form="http://nick-dunn.co.uk/xslt/form-controls" extension-element-prefixes="exsl str" extension-element-prefixes="exsl form">
in the same page am using form controls , when i include these two lines
xmlns:str="http://exslt.org/strings" extension-element-prefixes="exsl str"
am getting a blank (white) page without errors whether i have included in a proper way ?
You can only have one extension-element-prefixes
attribute, so if you concatenate them into one like so
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:str="http://exslt.org/strings" xmlns:form="http://nick-dunn.co.uk/xslt/form-controls" extension-element-prefixes="exsl str form">
Hope this helps.
thanks a lot , to all it works
Create an account or sign in to comment.
i have an event in which i can add the option value into the backend ,i want to retrieve the stored option value ( i did that using data source ) but i want to populate the selected value at the first position ,rest of them in the consecutive position how to do this in symphony