I have created the following XSLT to display search results from a form that contains two drop down boxes but I want the results to have paging. I have added paging to other pages in XSLT but my search results XSLT contains 4 different "When" statements and I want to try and not repeat the code as much as possible and make sure it is efficient so I am wondering how I go about doing this because each "When" statement would surely need a different "numberofrecords" variable and "count" parameter in the pagination XSLT? Can anyone offer me any suggestions or am I just going to have to repeat the pagination XSLT 4 times in my search results XSLT but with different variables specified?
<!-- GET CATEGORY QUERY STRING --> <xsl:variable name="categoryquery"> <xsl:choose> <xsl:when test="umbraco.library:Request('category') <= 0 or string(umbraco.library:Request('category')) = '' or string(umbraco.library:Request('category')) = 'NaN'">0</xsl:when> <xsl:otherwise> <xsl:value-of select="umbraco.library:Request('category')"/> </xsl:otherwise> </xsl:choose> </xsl:variable>
<!-- GET LOCATION QUERY STRING --> <xsl:variable name="locationquery"> <xsl:choose> <xsl:when test="umbraco.library:Request('location') <= 0 or string(umbraco.library:Request('location')) = '' or string(umbraco.library:Request('location')) = 'NaN'">0</xsl:when> <xsl:otherwise> <xsl:value-of select="umbraco.library:Request('location')"/> </xsl:otherwise> </xsl:choose> </xsl:variable>
<xsl:choose> <!-- RESULTS WHEN CATEGORY IS ANY AND LOCATION IS SELECTED --> <xsl:when test="$categoryquery = 'any' and $locationquery != 'any'"> <xsl:for-each select="umbraco.library:GetXmlNodeById(1148)//node[@nodeTypeAlias='Job' and string(data [@alias='umbracoNaviHide']) != '1' and string(data [@alias='location']) = $locationquery]">
<xsl:if test="count(umbraco.library:GetXmlNodeById(1148)//node [@nodeTypeAlias='Job' and string(data [@alias='umbracoNaviHide']) != '1' and string(data [@alias='location']) = $locationquery]) = 0"> <div class="jobsearchresult"> <p>Your search returned no results</p> <br /> <a href="/browse-all-jobs.aspx">Click here to browse all jobs</a> </div> </xsl:if>
</xsl:when>
<!-- RESULTS WHEN LOCATION IS ANY AND CATEGORY IS SELECTED --> <xsl:when test="$locationquery = 'any' and $categoryquery != 'any'">
<xsl:for-each select="umbraco.library:GetXmlNodeById(1148)//node [string(data [@alias='umbracoNaviHide']) != '1' and contains(data [@alias='category'], $categoryquery)]">
<xsl:if test="count(umbraco.library:GetXmlNodeById(1148)//node [string(data [@alias='umbracoNaviHide']) != '1' and contains(data [@alias='category'], $categoryquery)]) = '0'"> <div class="jobsearchresult"> <p>Your search returned no results</p> <br /> <a href="/browse-all-jobs.aspx">Click here to browse all jobs</a> </div> </xsl:if>
</xsl:when>
<!-- RESULTS WHEN CATEGORY AND LOCATION ARE BOTH ANY --> <xsl:when test="$categoryquery = 'any' and $locationquery = 'any'"> <xsl:for-each select="umbraco.library:GetXmlNodeById(1148)//node[@nodeTypeAlias='Job']">
I have gone ahead and sorted this myself, just thought I would post my XSLT up here in case anyone else ran into this issue in future or if anyone wanted could suggest a better more efficient way of doing this. The XSLT basically displays the results from a form that contains two drop down lists (one called category and one called location) and shows 10 results on the page then displays links to show the next 10 results.
<xsl:choose> <!-- RESULTS WHEN CATEGORY IS ANY AND LOCATION IS SELECTED --> <xsl:when test="$categoryquery = 'any' and $locationquery != 'any'"> <xsl:variable name="numberOfRecords" select="count(umbraco.library:GetXmlNodeById(1148)//node[@nodeTypeAlias='Job' and string(data [@alias='umbracoNaviHide']) != '1' and string(data [@alias='location']) = $locationquery])"/>
<xsl:if test="count(umbraco.library:GetXmlNodeById(1148)//node [@nodeTypeAlias='Job' and string(data [@alias='umbracoNaviHide']) != '1' and string(data [@alias='location']) = $locationquery]) = 0"> <div class="jobsearchresult"> <p>Your search returned no results</p> <br /> <a href="/browse-all-jobs.aspx">Click here to browse all jobs</a> </div> </xsl:if>
</xsl:when>
<!-- RESULTS WHEN LOCATION IS ANY AND CATEGORY IS SELECTED --> <xsl:when test="$locationquery = 'any' and $categoryquery != 'any'"> <xsl:variable name="numberOfRecords" select="count(umbraco.library:GetXmlNodeById(1148)//node [string(data [@alias='umbracoNaviHide']) != '1' and contains(data [@alias='category'], $categoryquery)])"/>
<xsl:if test="count(umbraco.library:GetXmlNodeById(1148)//node [string(data [@alias='umbracoNaviHide']) != '1' and contains(data [@alias='category'], $categoryquery)]) = '0'"> <div class="jobsearchresult"> <p>Your search returned no results</p> <br /> <a href="/browse-all-jobs.aspx">Click here to browse all jobs</a> </div> </xsl:if>
</xsl:when>
<!-- RESULTS WHEN CATEGORY AND LOCATION ARE BOTH ANY --> <xsl:when test="$categoryquery = 'any' and $locationquery = 'any'"> <xsl:variable name="numberOfRecords" select="count(umbraco.library:GetXmlNodeById(1148)//node[@nodeTypeAlias='Job'])"/>
Add pagination to search results XSLT
Hi,
I have created the following XSLT to display search results from a form that contains two drop down boxes but I want the results to have paging. I have added paging to other pages in XSLT but my search results XSLT contains 4 different "When" statements and I want to try and not repeat the code as much as possible and make sure it is efficient so I am wondering how I go about doing this because each "When" statement would surely need a different "numberofrecords" variable and "count" parameter in the pagination XSLT? Can anyone offer me any suggestions or am I just going to have to repeat the pagination XSLT 4 times in my search results XSLT but with different variables specified?
This is my search results XSLT:
And this is the pagination XSLT I usually use:
I have gone ahead and sorted this myself, just thought I would post my XSLT up here in case anyone else ran into this issue in future or if anyone wanted could suggest a better more efficient way of doing this. The XSLT basically displays the results from a form that contains two drop down lists (one called category and one called location) and shows 10 results on the page then displays links to show the next 10 results.
is working on a reply...