Copied to clipboard

Flag this post as spam?

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


  • Rachel Skuse 88 posts 118 karma points
    Jan 30, 2012 @ 13:06
    Rachel Skuse
    0

    How to filter results using drop down selections

    Hi,

    I am using the following xslt to return a list of demonstration dates at our shops, which are then ordered into 5 results per page.

    <xsl:param name="currentPage"/>

    <xsl:variable name="perpage" select="number('5')"/>
    <xsl:variable name="pageNumber">
      <xsl:choose>
        <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">

      <xsl:variable name="demoType" select="umbraco.library:GetPreValues('6646')"/>
      <select>
        <xsl:for-each select="$demoType//preValue">
          <option value="{@id}">
            <xsl:value-of select="current()"/>
          </option>
        </xsl:for-each>
      </select>

      <xsl:variable name="demonstrators" select="umbraco.library:GetPreValues('6632')"/>
      <select>
        <xsl:for-each select="$demonstrators//preValue">
          <option value="{@id}">
            <xsl:value-of select="current()"/>
          </option>
        </xsl:for-each>
      </select>

      <xsl:variable name="demoRegion" select="umbraco.library:GetPreValues('6649')"/>
      <select>
        <xsl:for-each select="$demoRegion//preValue">
          <option value="{@id}">
            <xsl:value-of select="current()"/>
          </option>
        </xsl:for-each>
      </select>

      <xsl:variable name="demoslist" select="umbraco.library:GetXmlAll()//Demonstration [@isDoc]"/>
      <xsl:if test="$demoslist">

        <xsl:for-each select="$demoslist">
          <xsl:sort select="umbraco.library:FormatDateTime(demoDate, 'yyyyMMdd')" order="ascending"/>
          <xsl:if test="position() &gt; $perpage * number($pageNumber) and position() &lt;= number($perpage * number($pageNumber) + $perpage)">

            <xsl:value-of select="umbraco.library:FormatDateTime(demoDate, 'dd/MM/yyyy')" /><br/>
            <xsl:value-of select="umbraco.library:FormatDateTime(demoDate, 'h:mm tt')" /> - <xsl:value-of select="umbraco.library:FormatDateTime(demoDate, 'h:mm tt')" /><br/>
            <xsl:value-of select="../@nodeName"/> <br/> <xsl:value-of select="demoType" /> with <xsl:value-of select="demonstrator" /><br/>
            <xsl:value-of select="demoOtherNotes" />

          </xsl:if>
        </xsl:for-each>

        <xsl:if test="count($demoslist) &gt; $perpage">
          <ul class="search-results-pagination">
            <xsl:call-template name="for.loop">
              <xsl:with-param name="i">1</xsl:with-param>
              <xsl:with-param name="page" select="$pageNumber + 1"></xsl:with-param>
              <xsl:with-param name="count" select="ceiling(count($demoslist) div $perpage)"></xsl:with-param>
            </xsl:call-template>
          </ul>
        </xsl:if>
      </xsl:if>
    </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>
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}">
            <xsl:attribute name="class">
              <xsl:if test="$i = 1">
                <xsl:value-of select="'first '"/>
              </xsl:if>
              <xsl:if test="$page = $i">
                <xsl:value-of select="'selected '"/>
              </xsl:if>
            </xsl:attribute>
            <xsl:value-of select="$i" />
          </a>
        </li>
      </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>

    What I would like to be able to do is filter these results based on selections made from a number of drop down lists. I have managed to create the lists, populating the data from datatypes but I am unsure how I can apply these selections to a search.

    Code for populating lists...

    <xsl:variable name="demoType" select="umbraco.library:GetPreValues('6646')"/>
    <select>
      <xsl:for-each select="$demoType//preValue">
        <option value="{@id}">
          <xsl:value-of select="current()"/>
        </option>
      </xsl:for-each>
    </select>

    <xsl:variable name="demonstrators" select="umbraco.library:GetPreValues('6632')"/>
    <select>
      <xsl:for-each select="$demonstrators//preValue">
        <option value="{@id}">
          <xsl:value-of select="current()"/>
        </option>
      </xsl:for-each>
    </select>

    <xsl:variable name="demoRegion" select="umbraco.library:GetPreValues('6649')"/>
    <select>
      <xsl:for-each select="$demoRegion//preValue">
        <option value="{@id}">
          <xsl:value-of select="current()"/>
        </option>
      </xsl:for-each>
    </select>

    Can anyone help me out?

    Thanks

    /R

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies