I have a HTML select dropdown:
<select name="sortby">
<option value=""></option>
<option value="onenightavg">Price: High to Low</option>
<option value="number_bedrooms">Bedrooms: High to Low</option>
<option value="number_bathrooms">Bathrooms: High to Low</option>
<option value="max_sleeps">Sleeps: High to Low</option>
</select>
When the user submits this it sends a URL query string to the page and it gets added to the XML of the page:
<querystring>
<sortby>number_bathrooms</sortby>
</querystring>
I then set an XSL variable in my XSLT:
<xsl:variable name="sortby">
<xsl:choose>
<xsl:when test="/querystring/sortby != ''">
<xsl:value-of select="/querystring/sortby" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'onenightavg'" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
In the above XST I am setting a variable called $sortby and testing whether the querystring exists. If it does exist then set the variable to its value. If it doesn’t exist then default it to “onenightavg”.
Then I use that variable in my sort:
<xsl:sort data-type="number" order="ascending" select="$sortby" />
This doesn’t work. It doesn’t sort my items, but when I hardcode the select to any one of the values like this it works:
<xsl:sort data-type="number" order="ascending" select="onenightavg" />
I would like to be able to dynamically sort based on an the value of the selected option in the dropdown.
How about this: