Search

<select name="fields[dmonth]">
    <option value="Jan">Jan</option>
    <option value="Feb">Feb</option> 
    <option value="Mar">Mar</option>
    <option value="Apr">Apr</option> 
    <option value="May">May</option>
    <option value="Jun">Jun</option> 
    <option value="Jul">Jul</option>
    <option value="Aug">Aug</option> 
    <option value="Sep">Sep</option>
    <option value="Oct">Oct</option> 
    <option value="Nov">Nov</option>
    <option value="Dec">Dec</option>
</select>

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

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.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details