Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • syn-rg 282 posts 425 karma points
    Feb 25, 2011 @ 04:57
    syn-rg
    0

    Create a "Show all" and "Show paged" button

    I've been using a "Show all" and "Show paged" button on the following page:
    http://isis.brandtoolbox.com.au/projects/projects.aspx

    I thought this function would make a great addition to the XSLTsearch.xslt. Allowing all the result matches to appear on the one page, or changed back to display across many pages.

    I'm no where near skilled enough to do this myself, I've managed to create it for my custom Projects page with help from a very skilled programmer. However I thought I'd try the forums first to see if anyone was able to implement this function within the XSLTsearch.xslt. As I believe it's a function that many websites would benefit from, and would hope that it could be something that could be adhered to the existing XSLTsearch package.

    What does everyone think?
    Can anyone assist?

    Cheers,
    JV

    Here's my code that I'm using on my "Projects" page:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:emint="urn:my-scripts"
    exclude-result-prefixes="msxml umbraco.library">
    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:variable name="FF_projectList" select="umbraco.library:RequestForm('projects')" />
    <xsl:variable name="FF_projectTypeList" select="umbraco.library:RequestForm('projectType')" />
    <xsl:variable name="FF_projectLocationList_Temp" select="umbraco.library:RequestForm('projectLocation')" />
    <xsl:variable name="FF_sortType" select="umbraco.library:RequestForm('sortType')" />
    <xsl:variable name="FF_projectShowAll" select="umbraco.library:RequestForm('projectShowAll')" />
    <xsl:variable name="QS_projectLocationList" select="umbraco.library:RequestQueryString('state')" />

    <xsl:variable name="FF_projectLocationList">
    <xsl:choose>
    <xsl:when test="$QS_projectLocationList = ''"><xsl:value-of select='$FF_projectLocationList_Temp' /></xsl:when>
    <xsl:otherwise><xsl:value-of select='$QS_projectLocationList' /></xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:param name="currentPage"/>
    <xsl:template match="/">



    <xsl:variable name="sectionId">
    <xsl:if test="($FF_projectList = 0 or $FF_projectList = '')">
    <xsl:value-of select="$currentPage/@id" />
    </xsl:if>
    <xsl:if test="($FF_projectList &gt; 0)">
    <xsl:value-of select="$FF_projectList" />
    </xsl:if>
    </xsl:variable>

    <input type="hidden" id="projectShowAll" name="projectShowAll" />

    <xsl:variable name="possibleNodes" select="$currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name() != 'ProjectGallery' and name() = 'ProjectPage']" />
    <xsl:variable name="matchedNodesIdList">
    <xsl:for-each select="$possibleNodes" >
    <xsl:call-template name="projectNode">
    <xsl:with-param name="project" select="."/>
    </xsl:call-template>
    </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="matchedNodes" select="$possibleNodes[contains($matchedNodesIdList, concat(@id, ';'))]" />

    <xsl:variable name="itemsPerPage">12</xsl:variable>
    <xsl:variable name="recordsPerPage">
    <xsl:choose>
    <xsl:when test="$FF_projectShowAll = 'true'">
    <xsl:value-of select="count($matchedNodes)" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$itemsPerPage" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="pageNumber">
    <xsl:choose>
    <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="numberOfRecords" select="count($matchedNodes)"/>
    <xsl:value-of select="umbraco.library:RegisterStyleSheetFile('slider1', '/css/project_gallery.css')"/>
    <div id="project_gallery">
    <xsl:if test="$numberOfRecords = 0">
    <div id="projects_error_msg">
    <p>No projects with that search criteria were found.</p>
    </div>
    </xsl:if>
    <ul>
    <xsl:for-each select="$matchedNodes">
    <xsl:sort select="@nodeName[$FF_sortType = 'Client' or $FF_sortType='']" order="ascending" />
    <xsl:sort select="completionDate[$FF_sortType = 'NewestToOldest' or $FF_sortType='']" order="descending" />

    <xsl:sort select="./../@nodeName [$FF_sortType = 'Sector']" order="ascending" />
    <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">
    <li>
    <div id="project">
    <!-- get first photo thumbnail -->
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:if test="count(./* [@isDoc]) &gt; 0">
    <img src="{concat(substring-before(./*/projectImage,'.'), '_thumb_180.jpg')}"/>
    </xsl:if>
    <xsl:if test="completionDate != ''">
    <h1><xsl:value-of select="umbraco.library:FormatDateTime(completionDate, 'MMMM yyyy')"/></h1>
    </xsl:if>
    <xsl:if test="projectClient != ''">
    <h2>
    <!-- <xsl:value-of select="projectClient" /> -->
    <xsl:value-of select="umbraco.library:StripHtml(pageTitle)" />
    </h2>
    </xsl:if>
    <xsl:if test="projectLocation != '' and projectState != ''">
    <p><xsl:value-of select="projectLocation" />,&nbsp;<xsl:value-of select="projectState" /></p>
    </xsl:if>
    </a>
    </div>
    </li>
    </xsl:if>
    </xsl:for-each>
    </ul>

    <xsl:if test="$numberOfRecords &gt; $recordsPerPage or $FF_projectShowAll != ''">
    <div id="page_numbers_nav">
    <xsl:if test="$numberOfRecords &gt; $recordsPerPage">
    <!--<xsl:if test="$pageNumber &gt; 1">
    <li>
    <xsl:call-template name="pageUrl">
    <xsl:with-param name="pageNumber" select="$pageNumber - 1"/>
    <xsl:with-param name="pageText" select="'previous'"/>
    <xsl:with-param name="currentPageNumber" select="$pageNumber"/>
    <xsl:with-param name="class" select="'previous'"/>
    <xsl:with-param name="currentPageUrl">
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)" />?
    </xsl:with-param>
    </xsl:call-template>
    </li>
    </xsl:if>-->

    <xsl:if test="$numberOfRecords &gt; $recordsPerPage">
    <xsl:call-template name="for.loop">
    <xsl:with-param name="i">1</xsl:with-param>
    <xsl:with-param name="page" select="$pageNumber"></xsl:with-param>
    <xsl:with-param name="count" select="ceiling(count($matchedNodes) div $recordsPerPage)"></xsl:with-param>
    </xsl:call-template>
    </xsl:if>



    <!--<xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
    <li>
    <xsl:call-template name="pageUrl">
    <xsl:with-param name="pageNumber" select="$pageNumber + 1"/>
    <xsl:with-param name="pageText" select="'next'"/>
    <xsl:with-param name="currentPageNumber" select="$pageNumber"/>
    <xsl:with-param name="class" select="'next'"/>
    <xsl:with-param name="currentPageUrl">
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)" />?
    </xsl:with-param>
    </xsl:call-template>
    </li>
    </xsl:if>-->
    </xsl:if>
    <xsl:variable name="currentUrl" select="umbraco.library:NiceUrl($currentPage/@id)" />

    <!-- Satjinder - Code for "SHOW ALL" function -->

    <xsl:choose>
    <xsl:when test="$FF_projectShowAll = ''" >
    <xsl:if test="$numberOfRecords &gt; $recordsPerPage">
    <li class="show_all" id="showAll_Buttons">
    <a>
    <xsl:attribute name="href">
    javascript:Projects_SetShowAll(true, '<xsl:value-of select="$currentUrl" /><xsl:if test="$QS_projectLocationList">?state=<xsl:value-of select='$QS_projectLocationList' /></xsl:if>');
    </xsl:attribute>
    Show all&nbsp;&nbsp;<span><xsl:value-of select="$numberOfRecords"/></span>
    </a>
    </li>
    </xsl:if>
    </xsl:when>
    <xsl:otherwise>
    <li>
    <a class="show_paged">
    <xsl:attribute name="href">
    javascript:Projects_SetShowAll(false, '<xsl:value-of select="$currentUrl" /><xsl:if test="$QS_projectLocationList">?state=<xsl:value-of select='$QS_projectLocationList' /></xsl:if>');
    </xsl:attribute>
    Show paged
    </a>
    </li>
    </xsl:otherwise>
    </xsl:choose>

    <!-- Close -->
    </div>
    </xsl:if>
    </div>

    <script type="text/javascript">

    function GotoNextPage(url)
    {
    //$("#searchImageClicked").val('search');
    document.forms[0].action=url;
    document.forms[0].submit();
    }

    function Projects_SetShowAll(flag, url){
    if (flag){
    $("#projectShowAll").val('true');
    }
    else{
    $("#projectShowAll").val('');
    }
    $("#aspnetForm").attr("action", url);
    $("#aspnetForm").submit();
    }

    </script>
    </xsl:template>

    <xsl:template name="for.loop">
    <xsl:param name="i"/>
    <xsl:param name="count"/>
    <xsl:param name="page"/>
    <xsl:if test="$i &lt;= $count">
    <li><xsl:if test="$page != $i">
    <xsl:call-template name="pageUrl">
    <xsl:with-param name="pageNumber" select="$i"/>
    <xsl:with-param name="pageText" select="$i"/>
    <xsl:with-param name="currentPageNumber" select="$page"/>
    <xsl:with-param name="class" select="'next_page'"/>
    <xsl:with-param name="currentPageUrl">
    <xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)" />?<xsl:if test="$QS_projectLocationList">state=<xsl:value-of select='$QS_projectLocationList' /></xsl:if>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:if></li>
    <xsl:if test="$page = $i">
    <span class="currentpage">
    <xsl:value-of select="$i" />
    </span>
    </xsl:if>
    </xsl:if>
    <xsl:if test="$i &lt;= $count">
    <xsl:call-template name="for.loop">
    <xsl:with-param name="i">
    <xsl:value-of select="$i + 1"/>
    </xsl:with-param>
    <xsl:with-param name="count">
    <xsl:value-of select="$count"/>
    </xsl:with-param>
    <xsl:with-param name="page">
    <xsl:value-of select="$page"/>
    </xsl:with-param>
    </xsl:call-template>
    </xsl:if>
    </xsl:template>

    <xsl:template name="projectNode">
    <xsl:param name="project"/>
    <xsl:variable name="projectLocationList"></xsl:variable>
    <xsl:if test="$projectLocationList = $FF_projectLocationList">dd</xsl:if>
    <xsl:if test="((emint:SearchTerminValue2($project/projectType, $FF_projectTypeList) = 'true') and (emint:CompareIfValueIsThere1($project/projectState, $FF_projectLocationList, '/projects/projects.aspx') = 'true'))">
    <xsl:value-of select="$project/@id" />;
    </xsl:if>
    </xsl:template>

    <xsl:template name="pageUrl">
    <xsl:param name="pageNumber" select="1"/>
    <xsl:param name="pageText" select="1"/>
    <xsl:param name="class" select="page" />
    <xsl:param name="currentPageNumber" select="1"/>
    <xsl:param name="currentPageUrl" select="''"/>
    <a>
    <xsl:attribute name="class">
    <xsl:value-of select="$class" />
    </xsl:attribute>
    <xsl:attribute name="href">
    javascript:GotoNextPage('<xsl:value-of select="$currentPageUrl"/>&amp;tid=<xsl:value-of select="$pageNumber"/>&amp;page=<xsl:value-of select="$pageNumber"/>');
    </xsl:attribute>
    <xsl:value-of select="$pageText"/>
    </a>
    </xsl:template>



    <msxsl:script language="C#" implements-prefix="emint">
    <![CDATA[


    public bool CompareIfValueIsThere(string term, string value)
    {
    if (string.IsNullOrEmpty(value))
    {
    return true;
    }
    if (value.ToUpper() == term.ToUpper())
    {
    return true;
    }
    return false;
    }

    public bool CompareIfValueIsThere1(string term, string value, string emptyValue)
    {
    if (string.IsNullOrEmpty(value))
    {
    return true;
    }
    if (value == emptyValue)
    {
    return true;
    }
    if (value.ToUpper() == term.ToUpper())
    {
    return true;
    }
    return false;
    }
    public bool SearchTerminValue(string value, string term)
    {
    string[] terms = term.Split('/');
    foreach (string item in terms)
    {
    bool found = SearchTerminValue1(value, item);
    if (!found)
    {
    return false;
    }
    }
    return true;
    }

    public bool SearchTerminValue1(string value, string term)
    {
    string[] terms = term.Split(' ');
    foreach (string item in terms)
    {
    int ind = value.IndexOf(item, StringComparison.InvariantCultureIgnoreCase);
    if (ind >= 0)
    {
    return true;
    }
    }
    return false;
    }


    public bool SearchTerminValue2(string value, string term)
    {
    string[] terms = term.Split(',');
    foreach (string item in terms)
    {
    int ind = value.IndexOf(item, StringComparison.InvariantCultureIgnoreCase);
    if (ind >= 0)
    {
    return true;
    }
    }
    return false;
    }


    ]]>
    </msxsl:script>
    </xsl:stylesheet>
Please Sign in or register to post replies

Write your reply to:

Draft