Hey guys,
I’m building a page that has some filter boxes on (check boxes). There are four sets of filters.
On my page I have a macro that reads in the values of query strings sent to the page and then displays the results accordingly. I have got this to work just fine using a set of and statements in an apply-template.
The problem I now have though is that it is too precise. To get a result back, I have to to check everything and then uncheck the one box I don’t want to filter on (because of the and filters). It also means that when the page loads, I get no results and I would like to load everything by default.
My ideal situation would be to test to see if the query string exists, if it does include it in the filter. If it doesn’t exist, don’t filter on it. I could probably do this with 16 seperate if statements where I pop a different apply-tempate in each one, but that sounds ridiculous to me.
My original code is below (I have only included two filters to keep the code to a minimum on here). What I have tried since is to store each of the filters in a variable as plain text, with a simple check for the query string being there, but it doesn’t seem to work. Any help would be much appreciated.
Thanks,
Tom
<xsl:variable name="CountriesSplit" select="umb:Split(umb:RequestQueryString('country'), ',')/value" />
<xsl:variable name="YearsSplit" select="umb:Split(umb:RequestQueryString('year'), ',')/value" />
<xsl:template match="/">
<!-- Pop some results in! -->
<xsl:apply-templates select="$resourceRoot//Resources[umb:Split(countries, ',')/value = $CountriesSplit and ./year = $YearsSplit]">
<xsl:sort select="year" order="descending" />
</xsl:apply-templates>
</xsl:template>
<!-- Template for a resource -->
<xsl:template match="Resources">
<p style="border-bottom: 1px dashed #ccc; padding-bottom: 10px;">
<a href="{umb:NiceUrl(@id)}"><xsl:value-of select="title"/></a><br />
<strong>Resource Type: </strong><xsl:value-of select="./../title" /><br />
<em><xsl:value-of select="year" /></em>
</p>
</xsl:template>
To pass values as a parameter, I have tried doing the following:
<xsl:variable name="YearsAlive">
<xsl:choose>
<xsl:when test="umb:RequestQueryString('year')">./year = $YearsSplit</xsl:when>
</xsl:choose>
</xsl:variable>
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/67702-testing-querystrings