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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to paginate results? 1

Status
Not open for further replies.

MrT2005

Programmer
Mar 8, 2005
22
CA
Using the following XSL as an exmaple, how could it be modified to include pagination of the results (ie. Previous, Next, 1,2,3,4 ) etc...

Keep in mind that I am using sorting and search parameters also.


<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:eek:utput method="html" encoding="ISO-8859-1" indent="yes"/>

<xsl:param name="keyword">none</xsl:param>
<xsl:param name="keyregion">none</xsl:param>
<xsl:param name="sterm">none</xsl:param>
<xsl:param name="sorder">none</xsl:param>


<xsl:template match="/">
<xsl:for-each select="fiches/fiche[texte/cattouristique=$keyword]">

<xsl:sort order="{$sorder}" select="
texte/fichetitre[$sterm='a'] |
texte/typeheberg[$sterm='b'] |
region/regionnseo[$sterm='c']
"/>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="myBkgnd_{position() mod 2 -1}">
<td width="*" class="pad">
<a>
<xsl:attribute name="href">
<xsl:text>page-g.php?key=</xsl:text>
<xsl:value-of select="numero"/><xsl:text>&amp;keyword=</xsl:text><xsl:value-of select="texte/cattouristique"/>
</xsl:attribute>
<xsl:value-of select="texte/fichetitre" />
</a>
</td>
<td width="200" align="center" class="pad"><xsl:value-of select="texte/typeheberg" /></td>
<td width="100" align="center" class="pad"><xsl:value-of select="region/regionnseo" /></td>
</tr>
</table>
</xsl:for-each>
</xsl:template>


</xsl:stylesheet>
 
Not clear what you want. Whats the purpose of this project? What information are you trying to display and how do you want to display it? XSL-FO might be the way to go.
 
the existing code (posted above) displays the results based on the parameters put in. This all works fine.

The thing that is missing is the XSL code to paginate the results.

Pagination is when you split the results into pages and have links like "Previous, Next, page 1, page 2, page 3, page 4".

XSL-FO is not an option as we dont have support for that on the server.
 
Install an XSL-FO on your server.

If you really can't do that, you're gonna have to figure out a way to split the data up into pages. If you want help with that, you're probably best off posting an example of the html you produce.
 
You _can_ do some sort of complicated count mechanism by passing variables in as to page size and page that you are on (i have done it in the past).

so for example, [NOT WORKING, INCREDIBLY SIMPLIFIED just here for the general gist]

Code:
<xsl:if test="count() > $pagesize and count() < $pagesize - $pagerange"> 
    <xsl:apply-templates/>
</xsl:if>

--- its not as easy as that tho, you have to do calculation and page ranges based on your page sizes, and that can be tricky. This method is wasteful and slow, as you are still processing nodes that are outside the page ranges.

However, its best to mark up your XML with <page number="1"/> tags really, especially if you are generating them on the fly with a database. That way, you can pick out only the pages you require.

Matt



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top