xslt pagination

Posted on 2011-09-19
Last Modified: 2013-11-18

I  have some very simple XSLT that I have created, displaying an XML feed nicely.
However, this XML feed can contant hundreds of records so I need to add some pagination to ensure it stays tidy. However, I have no idea where to start.

Any help would be great.

Attached is a snippet of the XML structure.
If you would like my XSLT then I can post that too.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <Product Page_Nr="41">¿    
   <ServiceName>Test Name</ServiceName>
   <Desc_Destinations>Test Desc</Desc_Destinations>¿
   <Desc_Snapshot>Blah blah blah</Desc_Snapshot>¿
   <Desc_Hotel_Facilities>test facilities</Desc_Hotel_Facilities>¿
   <Desc_Guest_Rooms>92 Rooms • Balcony • Fully equipped kitchen • Air-con • TV • Hairdryer • Iron and ironing board</Desc_Guest_Rooms>¿
   <Desc_Price_description>Superior Suite (Room Only)</Desc_Price_description>¿
  <Image_1 href="hotel-image.jpg"></Image_1>¿  </Product>

Open in new window

Question by:help-is-needed
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 60

Expert Comment

by:Geert Bormans
ID: 36560911
Pagination is just a matter of cutting the page, so usually the XSLT is not very difficult.
You need to pass a parameter to the XSLT that tells you which should be your first record to show, and how many records you want to show.

Rest depends on the (web) architecture you are using

Basically I need more detail.
How do you run the XSLT
And how do you expect this to happen?

Is this static HTML calling an XSLT on an input XML... then javascript and eg. sarissa could do magic
Do you have ASP? Something else

Paging is a piece of cake, but you need to tell us what you want to happen.

Author Comment

ID: 36561006
Hi Gertone,

Thanks for getting back to me.
I am not using ASP. But probably using HTML to call an XSLT on an XML input then javascript to do the transformation.

Can you show me an example of this working?

LVL 60

Accepted Solution

Geert Bormans earned 500 total points
ID: 36565580
This should get you started

Make sure that you have a function showPage() in your javascript
that takes two parameters (integers, the first Record and the number of records)
and that does the transform passing the two integer parameters to the XSLT

Of course you could easily add extra navigation, I did a naieve "previous" and "next"
but it is fairly simple to add a "first" and "last"
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""
    <xsl:param name="first">4</xsl:param>
    <xsl:param name="size">8</xsl:param>
    <xsl:template match="Root">
            <xsl:apply-templates select="Product[position() >= $first and position() &lt; $first + $size]"/>
            <xsl:call-template name="navigation"/>
    <xsl:template match="Product">
        <!-- do product stuff here -->
        <p><xsl:value-of select="Story[1]/ServiceName"/></p>
    <xsl:template name="navigation">
            <a href="_blank">
                <xsl:attribute name="onclick">
                    <xsl:value-of select="$first - $size"/>
                    <xsl:value-of select="$size"/>
            <xsl:text>   </xsl:text>
            <a href="_blank">
                <xsl:attribute name="onclick">
                    <xsl:value-of select="$first + $size"/>
                    <xsl:value-of select="$size"/>

Open in new window


Author Comment

ID: 36565829
Thanks Gertone,

I've downloaded the sarissa package and managed to write some js that is working.
Thanks for your help, very simple when you know how.

LVL 60

Expert Comment

by:Geert Bormans
ID: 36565837

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question