Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML pagination

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
how do you paginate the XML cos i have tried this xsl but it "start" parameter value does not reflect the changes. How do we modify it such that when we click the next button, it will go to the second page

<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>


<xsl:eek:utput method=&quot;html&quot; />
<xsl:param name=&quot;start&quot;>1</xsl:param>
<xsl:param name=&quot;perpage&quot;>10</xsl:param>

<xsl:variable name=&quot;totalitems&quot; select=&quot;count(//student)&quot;/>
<xsl:variable name=&quot;end&quot;>
<xsl:choose>
<xsl:when test=&quot;($start + $perpage) &gt; $totalitems&quot;>
<xsl:value-of select=&quot;$totalitems&quot;/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select=&quot;$start + $perpage - 1&quot;/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:variable>

<!-- begin root template -->

<xsl:template match=&quot;/&quot;>



<h3>Showing records <xsl:value-of select=&quot;$start&quot;/>- <xsl:value-of
select=&quot;$end&quot;/> of
<xsl:value-of select=&quot;$totalitems&quot;/></h3>

<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<tr><th>Product ID</th><th>Description</th><th>Price</th></tr>
<xsl:for-each select=&quot;school/student[position() >= $start and
position() &lt;= $end]&quot;>
<tr>
<td><xsl:value-of select=&quot;name&quot;/></td>
</tr>
</xsl:for-each>
</table>

<!-- if there are records before the block we are viewing, provide a
'prev.' link -->
<xsl:if test=&quot;$start > 1&quot;>
<a href=&quot;school.xml?start={$start - $perpage};perpage={$perpage}&quot;>prev.</a>
</xsl:if>

<!-- process *all* the <item> elements in the document to build the
'google-style' navbar -->
<xsl:apply-templates select=&quot;student&quot;/>

<!-- if there are more records, provide a 'next' link -->
<xsl:if test=&quot;$totalitems > $end&quot;>
<a href=&quot;school.xml?start2={$end + 1};perpage={$perpage}&quot; name=&quot;siao&quot;>next</a>
</xsl:if>


</xsl:template>

<!-- end root template -->

<!-- the 'item' template that builds the numbered navbar links -->
<xsl:template match=&quot;student&quot;>
<xsl:if test=&quot;position() mod $perpage = 1 or $perpage = 1&quot;>
<xsl:variable name=&quot;pagenum&quot;>
<xsl:value-of select=&quot;ceiling(position() div $perpage)&quot;/>
</xsl:variable>
<a href=&quot;school.xml?start={position()};perpage={$perpage}&quot;>
<xsl:value-of select=&quot;$pagenum&quot;/>
<!-- force whitespace in between the numbered links -->
<xsl:text> </xsl:text>
</a>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top