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
    Nov 19, 2010 @ 04:19
    syn-rg
    0

    Filter and sort child page list using dropdown menu

    I am creating a filter for a Projects page that displays the grandchild nodes as thumbnails.

    I'm using dropdown menus to filter and sort the displayed thumbnails. There are 4 dropdown menus.

    • All sectors
    • Office
    • Retail
    • Hotels and Leisure
    • Science and Healthcare
    • Education
    • All project types
    • Fitout
    • Refurbishment
    • New build
    • All locations
    • NSW
    • VIC
    • QLD
    • SA
    • WA
    • Sort by
    • Newest to oldest
    • Client name
    • Sector

    All sectors dropdown menu simply lists the child nodes and links to the page (currently not working).

    All project types and All locations menus have dropdown datatypes listing those values. I need those values to populate the menus. Alias' projectType and projectState.

    Sort by menu will have the option to sort the list by Newest to oldest, Client name and Sector. These values have datatypes, the Newest to oldest will be filtered by a datatype alias completionDate and Client name has a datatype alias projectClient. The sector can be filtered by it's child node.

    I'm not sure how to populate the dropdown menu's with all those values, I've got the All sectors displaying but not linking.

    The idea is of course for page to sort the thumbnails according to what values are selected in the dropdown. All thumbnails that do not contain those values won't be displayed.

    Does anyone have any suggestions on how I can get this working?

    Here's the code for the filter macro:

    <?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:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets "
    >


    <xsl:output method="xml" omit-xml-declaration="yes"/>
        
    <xsl:variable name="projectTypeList" select="umbraco.library:RequestForm('projectTypeList')" />
    <xsl:variable name="projectLocationList" select="umbraco.library:RequestForm('projectLocationList')" />
    <xsl:variable name="sortType" select="umbraco.library:RequestForm('sortType')" />    
        
    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
      <div id="project_gallery_filter">
        <form action="#">
          <fieldset>
            <select name="speedC" id="speedC">
              <option selected="selected" value="0">All sectors</option>
              <xsl:for-each select="$currentPage/* [@isDoc and string(./umbracoNaviHide) != '1']">
                
                <option value="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="@nodeName"/>
                </option>
                
              </xsl:for-each>
            </select>
          </fieldset>
          <fieldset>
            <xsl:variable name="projectTypeList" select="$currentPage//node/data[@alias='projectType' and not(.=following::node/projectType)]" />
            <select name="speedC" id="speedC">
              <option value="">All project types</option>
              <xsl:for-each select="$projectTypeList">
                <xsl:sort  order="ascending" data-type="text" />
                <option value="{.}">
                  <xsl:value-of select="." />
                </option>       
              </xsl:for-each>
            </select>        
          </fieldset>
          
          <fieldset>
            <xsl:variable name="projectLocationList" select="$currentPage//node/data[@alias='projectLocation' and not(.=following::node/projectLocation)]" />
            <select name="speedC" id="speedC">
              <option value="">All locations</option>
              <xsl:for-each select="$projectLocationList">
                <xsl:sort  order="ascending" data-type="text" />
                <option value="{.}">
                  <xsl:value-of select="." />
                </option>       
              </xsl:for-each>
            </select>        
          </fieldset>
          
          <fieldset>
            <select name="speedC" id="speedC">
              <option value="">Sort by</option>
              <xsl:for-each select="$currentPage/* [@isDoc and string(./umbracoNaviHide) != '1']">
                
                <option value="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="@nodeName"/>
                </option>
                
              </xsl:for-each>
            </select>        
          </fieldset>
          
        </form>
      </div>
      

      
    </xsl:template>

    </xsl:stylesheet>

    Here's the code for the page that displays the grandchild node information as thumnails:

    <?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"
      exclude-result-prefixes="msxml umbraco.library">
      <xsl:output method="xml" omit-xml-declaration="yes"/>

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

        <xsl:variable name="recordsPerPage" select="12"/>
        <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($currentPage/*[@isDoc and string(./umbracoNaviHide) != '1'])"/>
        <xsl:value-of select="umbraco.library:RegisterStyleSheetFile('slider1', '/css/project_gallery.css')"/>
            <div id="project_gallery">
        <ul>
          <xsl:for-each select="$currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and string(@template) != '0' and name() != 'ProjectGallery']">
            
            
            
            <xsl:sort select="completionDate" order="descending"/>

            
            
            
            <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" /></h2>
                  </xsl:if>
                  <xsl:if test="projectLocation != ''">
                    <p><xsl:value-of select="projectLocation" /></p>
                  </xsl:if>
                </a>
              </div>
            </li>
            </xsl:if>
          </xsl:for-each>
        </ul>
            
        <div id="page_numbers_nav">
          
        <xsl:if test="$pageNumber &gt; 1">
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}?tid={$pageNumber - 1}&amp;page={$pageNumber - 1}" class="previous">previous</a>
        </xsl:if>

        <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($currentPage/*[@isDoc and string(./umbracoNaviHide) != '1']) div $recordsPerPage)"></xsl:with-param>
        </xsl:call-template>

        <xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}?tid={$pageNumber + 1}&amp;page={$pageNumber + 1}" class="next">next</a>
        </xsl:if>
        </div>
        </div>
      </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">
          <xsl:if test="$page != $i">
            <a href="{umbraco.library:NiceUrl($currentPage/@id)}?tid={$i}&amp;page={$i}" class="next_page">
              <xsl:value-of select="$i" />
            </a>
          </xsl:if>
          <xsl:if test="$page = $i">
            <xsl:value-of select="$i" />
          </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:stylesheet>

     

    Cheers!
    JV

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 19, 2010 @ 14:24
    Tom Fulton
    0

    Just at a quick glance it looks like you are mixing new & old schemas in the first snippet (/node/data...)

    Wherever you aren't getting the values you expect, you can output a textarea with the raw XML to help you troubleshoot, ie

    <textarea><xsl:copy-of select="$projectTypeList"/></textarea>

Please Sign in or register to post replies

Write your reply to:

Draft