Tools







Paging for Search Results Xslt – Alternative of Search Paging webpart

SharePoint Search implements a custom search paging webpart, when customising the xslt the paging webpart does not execute as per expected.  A sample code for number based Paging that simulates the out of the box search pagig webpart, that can be plugged into the xslt instead of using the paging webpart is listed below,

 <!– Section for Implementing Number based paging–>
  <xsl:param name =”CurrentPage”/>
  <xsl:param name =”CurrentUrl”/>
  <xsl:param name =”PageSize” />
  <xsl:param name =”MaxPages” />
  <xsl:param name =”Totalresults”/>
  <xsl:param name =”Statistics”/>
  <xsl:param name =”WebpartTitle”/>
  <xsl:param name =”DatabaseTime”/>

  <xsl:template name=”for.loop”>
    <xsl:param name=”position” />
    <xsl:param name=”TotalPages” />
    <xsl:param name =”j”/>

    <!–begin_: Line_by_Line_Output –>
    <xsl:if test=”(ceiling($Totalresults div $PageSize) + 1 > $position)”>
      <xsl:variable name =”CurrUrl” select =”($CurrentUrl)”/>
      <xsl:choose>
        <xsl:when test=”($position > ($CurrentPage – ceiling($MaxPages div 2)) or $position > ($TotalPages – $MaxPages)) and (($position &lt; $CurrentPage + $MaxPages div 2) or ($position &lt; 1 + $MaxPages))”>
          <xsl:if test=”$position=$CurrentPage”>
            <xsl:text> </xsl:text>
            <!–<xsl:text disable-output-escaping=”yes”>”></xsl:text>–>
            <xsl:value-of select=” $j “/>
            <xsl:text disable-output-escaping=”yes”>&lt;/a>  </xsl:text>
          </xsl:if>

          <xsl:if test=”$position !=$CurrentPage”>
            <xsl:text disable-output-escaping=”yes”>&lt;a href=”</xsl:text>
            <xsl:value-of select=”$CurrUrl”/>
            <xsl:text disable-output-escaping=”yes”>page=</xsl:text>
            <xsl:value-of select =”($position)”/>
            <xsl:text disable-output-escaping=”yes”>”> </xsl:text>
            <xsl:value-of select=”$position”/>
            <xsl:text disable-output-escaping=”yes”>&lt;/a>  </xsl:text>
          </xsl:if>
        </xsl:when>

        <xsl:when test=”($position > ($CurrentPage – ceiling($MaxPages div 2) – 1) or $position > ($TotalPages – $MaxPages) – 1 ) and (($position &lt; $CurrentPage + $MaxPages div 2 + 1) or ($position &lt; 2 + $MaxPages))”>
          <xsl:if test =”($CurrentPage > $position)”>
            <xsl:variable name =”imgUrl” select =”concat(($CurrentUrl),’page=’,($CurrentPage -1))”/>
            <a href=”{$imgUrl}”>
              <img style=”vertical-align: middle;” src=”/_layouts/images/OneCollaboration/BlueArrowLeft.gif” alt=”" border=”0″/>
            </a>

          </xsl:if>
          <xsl:if test =”($position > $CurrentPage )”>
            <xsl:variable name =”imgUrl” select =”concat(($CurrentUrl),’page=’,($CurrentPage +1))”/>
            <a href=”{$imgUrl}”>
              <img style=”vertical-align: middle;” src=”/_layouts/images/OneCollaboration/BlueArrowRight.gif” alt=”" border=”0″/>
            </a>
            <br></br>
            <br></br>
          </xsl:if>
        </xsl:when>

      </xsl:choose>

    </xsl:if>

    <!–begin_: RepeatTheLoopUntilFinished–>
    <xsl:if test=”(ceiling($Totalresults div $PageSize) + 1 > $position)”>
      <xsl:call-template name=”for.loop”>
        <xsl:with-param name=”position”>
          <xsl:value-of select=”($position + 1)”/>
        </xsl:with-param>
        <xsl:with-param name=”TotalPages”>
          <xsl:value-of select=”$TotalPages”/>
        </xsl:with-param>
        <xsl:with-param name =”j”>
          <xsl:value-of select =”($j + 1)”/>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name=”Pages”>
    <xsl:variable name=”TotalItems” select=”count(Result)” />
    <xsl:variable name=”Pages” select=”ceiling($TotalItems div $PageSize)” />

    <!– select first element of each page –>
    <xsl:for-each select=”Result[((position()-1) mod $PageSize = 0)]“>
      <!–<xsl:choose>
      <xsl:when test =”(position()-1 mod $PageSize =0)”>–>

      <!– display the appropriate portion of page links; disable link to active page –>
      <xsl:variable name =”CurrUrl” select =”($CurrentUrl)”/>
      <xsl:choose>
        <xsl:when test=”(position() > ($CurrentPage – ceiling($MaxPages div 2)) or position() > (last() – $MaxPages)) and ((position() &lt; $CurrentPage + $MaxPages div 2) or (position() &lt; 1 + $MaxPages))”>
          <xsl:text></xsl:text>
          <xsl:if test=”position()=$CurrentPage”>
            <xsl:text> </xsl:text>
            <xsl:value-of select=”position()”/>
            <xsl:text> </xsl:text>
          </xsl:if>

          <xsl:if test=”position()!=$CurrentPage”>
            <xsl:text disable-output-escaping=”yes”>&lt;a href=”</xsl:text>
            <xsl:value-of select=”$CurrUrl”/>
            <xsl:text disable-output-escaping=”yes”>page=</xsl:text>
            <xsl:value-of select =”(position())”/>
            <xsl:text disable-output-escaping=”yes”>”></xsl:text>
            <xsl:value-of select=”position()”/>
            <xsl:text disable-output-escaping=”yes”>&lt;/a>  </xsl:text>
          </xsl:if>
        </xsl:when>

        <xsl:when test=”(position() > ($CurrentPage – ceiling($MaxPages div 2) – 1) or position() > (last() – $MaxPages) – 1 ) and ((position() &lt; $CurrentPage + $MaxPages div 2 + 1) or (position() &lt; 2 + $MaxPages))”>
          <xsl:text disable-output-escaping=”yes”>&lt;a href=”</xsl:text>
          <xsl:value-of select=”$CurrUrl”/>
          <xsl:text disable-output-escaping=”yes”>page=</xsl:text>
          <xsl:value-of select=”position()”/>
          <xsl:if test =”($CurrentPage > position())”>
            <xsl:text disable-output-escaping=”yes”>”></xsl:text>Prev<xsl:text disable-output-escaping=”yes”>&lt;/a> </xsl:text>
          </xsl:if>
          <xsl:if test =”(position()>$CurrentPage)”>
            <xsl:text disable-output-escaping=”yes”>”></xsl:text>Next<xsl:text disable-output-escaping=”yes”>&lt;/a> </xsl:text>
            <br></br>
            <br></br>
          </xsl:if>
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
    <!–</xsl:when>
    </xsl:choose>–>
  </xsl:template>

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>