Solved

xslt pagination

Posted on 2011-09-19
5
340 Views
Last Modified: 2013-11-18
Hi,

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.

Thanks
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
 <Product Page_Nr="41">¿    
  <Story>¿
   <ServiceName>Test Name</ServiceName>
   <Product_Rating>5</Product_Rating>¿
   <Desc_Destinations>Test Desc</Desc_Destinations>¿
  </Story>
  <Story>
   <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>¿
   <Price>£118</Price>
   <Desc_Price_description>Superior Suite (Room Only)</Desc_Price_description>¿
  </Story>¿
  <Image_1 href="hotel-image.jpg"></Image_1>¿  </Product>
</Root>

Open in new window

0
Comment
Question by:help-is-needed
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
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.
0
 

Author Comment

by:help-is-needed
Comment Utility
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?

Thanks
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
Comment Utility
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="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="1.0">
    <xsl:param name="first">4</xsl:param>
    <xsl:param name="size">8</xsl:param>
    
    <xsl:template match="Root">
        <div>
            <xsl:apply-templates select="Product[position() >= $first and position() &lt; $first + $size]"/>
            <xsl:call-template name="navigation"/>
        </div>
    </xsl:template>
    
    <xsl:template match="Product">
        <!-- do product stuff here -->
        <p><xsl:value-of select="Story[1]/ServiceName"/></p>
    </xsl:template>
    
    <xsl:template name="navigation">
        <div>
            <a href="_blank">
                <xsl:attribute name="onclick">
                    <xsl:text>showPage(</xsl:text>
                    <xsl:value-of select="$first - $size"/>
                    <xsl:text>,</xsl:text>
                    <xsl:value-of select="$size"/>
                    <xsl:text>);</xsl:text>
                </xsl:attribute>
                <xsl:text>previous</xsl:text>
            </a>
            <xsl:text>   </xsl:text>
            <a href="_blank">
                <xsl:attribute name="onclick">
                    <xsl:text>showPage(</xsl:text>
                    <xsl:value-of select="$first + $size"/>
                    <xsl:text>,</xsl:text>
                    <xsl:value-of select="$size"/>
                    <xsl:text>);</xsl:text>
                </xsl:attribute>
                <xsl:text>next</xsl:text>
            </a>
        </div>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:help-is-needed
Comment Utility
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.

Thanks
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
welcome
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now