By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,315 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,315 IT Pros & Developers. It's quick & easy.

pagination using XSL

P: 10
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code.

Below is the code that i have written for pagination but it displays the link of all the pages at one go i.e. if i have 8 pages showing 10 results per page than it shows links for all 8 pages.

Previous 1-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 Next

i want to restrict that number to 5 and whenever the user clicks the 31-50 link then it should delete the entry for 1-10 and new entry for 51-60 should come up.

I am unable to implement this functionality. can anyone help me regarding this? Please guide if i am i am doing right or not?
Please provide me with links to tutorials on pagination concepts, it would be a great help to me..

The code is :

<!-- Calculate first records -->
<xsl:variable name="firstitem" select="/Properties/Data/External/paginate/nextIndex"/>
<xsl:variable name="lastitem" select="$firstitem + 10"/>

<!-- Calculate total number of records -->
<xsl:variable name="total" select="count(/Properties/Data/Datum[@Name='Summary']/DCR/cntSummary/cntSummaryContent)"/>

<xsl:template match="/">
<table id="p-columns" cellspacing="10">
<tr>
<td id="p-center">
<div class="p-article-summary-without">
<script type="text/javascript">
function callScript(a)
{ document.pagination.nextIndex.value = a * 10; document.pagination.submit();
}
</script>
<form name="pagination">
<input name="nextIndex" type="hidden" value="0"/>
</form>

<!-- Display the 'Results(xx to yy) of zz' -->
<h3> <strong>Results</strong> (
<strong>
<xsl:value-of select="$firstitem + 1"/>-
<xsl:choose><xsl:when test="$firstitem + 9 &lt; $total">
<xsl:value-of select="$firstitem + 10"/>
</xsl:when><xsl:otherwise> <xsl:value-of select="$total"/></xsl:otherwise>
</xsl:choose>
</strong>) of <xsl:value-of select="$total"/>
</h3>

<table cellspacing="0">
<xsl:variable name="path" select="/Properties/Data/Datum[@Name='Sorting']/Option[@Selected='true']/Value"/>
<xsl:choose>
<xsl:when test="$path='date'">
<xsl:for-each select="Properties/Data/Datum[@Name='Summary']/DCR/cntSummary/cntSummaryContent">
<xsl:sort order="descending" select="cntSummaryHeading/itmDate"/>
<xsl:if test="position() &gt; $firstitem and position() &lt;= $lastitem ">
<tr>
<!-- If first instance, then put the class="p-top" -->
<xsl:if test="position() = $firstitem + 1"><xsl:attribute name="class">p-top</xsl:attribute>
</xsl:if>
</tr>
<tr>
<td class="p-text">
<h5>
<a target="main">
<xsl:choose>
<xsl:when test="cntSummaryHeading/itmLinkType='external'">
<xsl:attribute name="href">
<xsl:value-of select = "cntSummaryHeading/itmHyperlink"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="cntSummaryHeading/itmLinkType='internal'">
<xsl:attribute name="href"> <xsl:value-of select = "cntSummaryHeading/dependent_itmPagelink"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:attribute name="title">
<xsl:value-of select="cntSummaryHeading/itmText"/></xsl:attribute>
<xsl:attribute name="target">
<xsl:value-of select="cntSummaryHeading/itmTarget"/>
</xsl:attribute>
<xsl:value-of select="cntSummaryHeading/itmText"/>
</a>
</h5>
</td>
</tr></table>
</xsl:if>
</div>

<xsl:if test="$total &gt; 10">
<div id="srcPaginator">
<table class="p-paginator" cellspacing="0">
<tr>
<!-- Find how many tabs are required -->

<xsl:variable name="tabs" select="floor(($total - 1) div 10) + 1"/>
<td class="p-text">More results:</td>

<!-- Previous if required -->
<xsl:if test="floor($firstitem div 10)!= '0'">
<td class="p-previous">
<a>
<xsl:attribute name="href">javascript:callScript(<xsl:value-of select="floor($firstitem div 10) - 1"/>);</xsl:attribute>
&lt; previous
</a>
</td>
</xsl:if>

<!-- Create the paginator tabs -->
<xsl:call-template name="paginator.loop">
<xsl:with-param name="i">1</xsl:with-param>
<xsl:with-param name="count"><xsl:value-of select="$tabs * 10"/></xsl:with-param>
</xsl:call-template>

<!-- More if required -->
<xsl:if test="floor($lastitem div 10)!= $tabs">
<td class="p-next">
<a>
<xsl:attribute name="href">javascript:callScript(<xsl:value-of select="floor($lastitem div 10)"/>);</xsl:attribute>
next >
</a>
</td>
</xsl:if>

</tr></table>
</div>
</xsl:if>
</td>
</tr>
</table>
</xsl:template>

<!-- Begin: Define The paginator loop for creating paginator -->
<xsl:template name="paginator.loop">

<xsl:param name="i"/>
<xsl:param name="count"/>

<!-- Create the form -->
<xsl:if test="$i &lt; $count">
<td>
<!-- Find which tab is corresponding to current page -->
<xsl:choose>
<xsl:when test="$i = $firstitem + 1">
<!-- This tab corresponds to current page -->
<!-- No hyperlink -->
<!-- class="p-active" -->
<xsl:attribute name="class">p-active</xsl:attribute>

<xsl:value-of select="$i"/>
-
<xsl:choose>
<xsl:when test="$i+9 &lt; $total">
<xsl:value-of select="$i+9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$total"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- This tab does not corresponds to current page -->
<!-- Its a hyperlink -->
<!-- class="p-link" -->
<xsl:attribute name="class">p-link</xsl:attribute>
<a>
<xsl:attribute name="href">javascript:callScript(<xsl:value-of select="floor($i div 10)"/>);</xsl:attribute>

<xsl:value-of select="$i"/>
-
<xsl:choose>
<xsl:when test="$i+9 &lt; $total">
<xsl:value-of select="$i+9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$total"/>
</xsl:otherwise>
</xsl:choose>
</a>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:if>

<!-- Repeat the loop until finished -->
<xsl:if test="$i &lt; $count">
<xsl:call-template name="paginator.loop">
<xsl:with-param name="i">
<xsl:value-of select="$i + 10"/>
</xsl:with-param>
<xsl:with-param name="count">
<xsl:value-of select="$count"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
Jul 16 '07 #1
Share this Question
Share on Google+
1 Reply


jkmyoung
Expert 100+
P: 2,057
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="Properties/Data/Datum[@Name='Summary']/DCR/cntSummary/cntSummaryContent"> 
-->

Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="Properties/Data/Datum[@Name='Summary']/DCR/cntSummary/cntSummaryContent[position() &gt;= $firstitem and position() &lt;= $lastitem"> 
Jul 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.