Copied to clipboard

Flag this post as spam?

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


  • Azad 2 posts 22 karma points
    May 27, 2015 @ 13:31
    Azad
    0

    XSLT Pagination page number issue

    Hi today i create pagination in XSLT from this blog: http://www.nibble.be/?p=11

    But my script just show (Previous 1 Next)

    There shoul be 5 pages but just showing one in pagination, please look into my code and guide me.

     

     

    ==========================================================================

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


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>


    <xsl:variable name="maxLevel" select="2" />
    <xsl:variable name="testimonialPic" select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '4']/testimonialPic"/>
    <xsl:variable name="testimonialClasses" select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '3']/testimonialClasses"/>



    <xsl:template match="/">
     
       
        <xsl:variable name="recordsPerPage" select="1"/>

     

    <xsl:variable name="pageNumber">

    <xsl:choose>

    <!-- first page -->

    <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:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>-->


    <!-- what was passed in -->

    <xsl:otherwise>

    <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>

    </xsl:otherwise>

    </xsl:choose>

     

    </xsl:variable> &nbsp;

     

    <xsl:variable name="numberOfRecords" select="count($currentPage/*)"/>

     
         

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
        <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber) and position() &lt;= number($recordsPerPage * number($pageNumber) + $recordsPerPage )">
        <xsl:choose>
         
                   
               
                <xsl:when test="(position( ) mod 2) = 1">

    <div class="col-sm-12 testimonial">
      <div class="col-sm-4 testimonial-pic">
        <div class="image">
                    <xsl:attribute name="style">background-image:url(
                      <xsl:value-of select="testimonialPic"/>
                    )</xsl:attribute>                                                               
                    <xsl:text> </xsl:text></div>
      </div>
      <div class="col-sm-8 testimonial-content">
        <div class="test-bor-lbv"><xsl:text> </xsl:text></div>
        <div class="test-bor-blh"><xsl:text> </xsl:text></div>
        <div class="test-bor-trh"><xsl:text> </xsl:text></div>
        <div class="test-bor-rtv"><xsl:text> </xsl:text></div>
        <div class="border">
          <div class="test-tab">
            <p>
                                   
                                    <xsl:attribute name="class">
                                    <xsl:value-of select="testimonialClasses"/>
                                    </xsl:attribute>   
                                   
                                    <xsl:value-of select="testimonialText"/><span>~ <xsl:value-of select="testimonialAuthor"/></span></p>
          </div>
        </div>
      </div>
    </div>
            </xsl:when>
                                   
                                   
                                   
                                   
                                   
                                   
            <xsl:otherwise>

        <div class="col-sm-12 testimonial">
      <div class="col-sm-4 testimonial-pic">
        <div class="image">
                   
                    <xsl:attribute name="style">background-image:url(
                      <xsl:value-of select="testimonialPic"/>
                    )</xsl:attribute>
                   
                    <xsl:text> </xsl:text></div>
      </div>
      <div class="col-sm-8 testimonial-content">
        <div class="test-bor-lbv"><xsl:text> </xsl:text></div>
        <div class="test-bor-blh"><xsl:text> </xsl:text></div>
        <div class="test-bor-trh"><xsl:text> </xsl:text></div>
        <div class="test-bor-rtv"><xsl:text> </xsl:text></div>
        <div class="border">
          <div class="test-tab">
            <p>
                                   
                                    <xsl:attribute name="class">
                                    <xsl:value-of select="testimonialClasses"/>
                                    </xsl:attribute>   
                                   
                                    <xsl:value-of select="testimonialText"/><span>~ <xsl:value-of select="testimonialAuthor"/></span></p>
          </div>
        </div>
      </div>
    </div>
            </xsl:otherwise>
                                   
                                   
                                   
                                   
        </xsl:choose>
        </xsl:if>
     
       
    </xsl:for-each>
      
        
     
       
         

    <xsl:if test="$pageNumber &gt; 0">

    <a href="?page={$pageNumber -1}">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 +1"></xsl:with-param>

    <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>

    </xsl:call-template>

     

    <xsl:if test="(($pageNumber +1 ) * $recordsPerPage) &lt; ($numberOfRecords)">

    <a href="?page={$pageNumber +1}">next</a>

    </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">

     

    <xsl:if test="$page != $i">

    <a href="{umbraco.library:NiceUrl($currentPage/*)}?page={$i - 1}" >

     

    <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>

     

     

    ===========================================================================

  • Chriztian Steinmeier 2733 posts 8352 karma points MVP 5x admin c-trib
    May 27, 2015 @ 13:51
    Chriztian Steinmeier
    0

    Hi Azad - welcome to Our!

    Find this line:

    <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>
    

    And change $currentPage/node to $currentPage/*[@isDoc]

    Also, find the places where $currentPage/* isn't followed by [@isDoc] (there's a few of them) and add it, e.g.:

    <xsl:variable name="numberOfRecords" select="count($currentPage/*)"/>
    

    should be:

    <xsl:variable name="numberOfRecords" select="count($currentPage/*[@isDoc])"/>
    

    I've only scanned it, but those are the most obvious places.

    If you're looking for a more modular approach to this, I've created a helper file to handle pagination: PaginationHelper that can be included in your main file, and it will handle all the nitty gritty stuff...

    Hope this helps,

    /Chriztian

  • Azad 2 posts 22 karma points
    May 27, 2015 @ 14:31
    Azad
    0

    Hi Chriztian,

     

    Thank you so much for your quick reply.

    I changed the lines what you told but few other errors appear in umbraco, when i save the XSLT, can you suggest some thing more close.

    Your PaginationHelper project is too good but i was unsuccessful to use it, do you have any tutorial for this.

     

    Thanks,

    Azad Kolachi

     

  • Chriztian Steinmeier 2733 posts 8352 karma points MVP 5x admin c-trib
    May 27, 2015 @ 14:46
    Chriztian Steinmeier
    0

    Hi again,

    So if you're keen on giving the helper a try, here's how:

    • Download the _PaginationHelper.xslt from the dist folder and save it in the xslt folder of Umbraco
    • Construct your macro XSLT something like this:

    Macro:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="html" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
    
            <xsl:call-template name="PaginateSelection">
                <xsl:with-param name="selection" select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]" />
                <xsl:with-param name="perPage" select="5" />
            </xsl:call-template>
    
        </xsl:template>
    
        <!-- Template for the output of a single item on the page -->
        <xsl:template match="*[@isDoc]" priority="-1">
            <div class="col-sm-12 testimonial">
                <div class="col-sm-4 testimonial-pic">
    
                    <xsl:value-of select="concat('Page: ', @nodeName)" />
    
                </div>
            </div>
        </xsl:template>
    
        <!-- Include all the magic... -->
        <xsl:include href="_PaginationHelper.xslt" />
    
    </xsl:stylesheet>
    

    NOTE: When using an include like this, you need to tick the "Skip testing" box when saving the XSLT file if you're not saving directly on the filesystem (e.g. with FTP or similar).

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft