Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates

asked on 

Pagination in xslt

Hi,

I have below xml and xslt working good. I need to add pagination in the result of my xslt transformation.

Can you please help me with pagination logic in my below xslt?

Thanks & Regards

<xsl:choose>
	<xsl:when test="$type = 'open' ">

		<xsl:for-each select="//SUMMARY[CATEGORY/@CATEGORYID = $categoryID or $categoryID = 0][SUBCATEGORYID = $subCategoryID or $subCategoryID = 0][//SUMMARY/FORMATTEDDATE >= $today]">
			<xsl:sort select="//SUMMARY/FORMATTEDDATE " />
			SOME STUFF
		</xsl:for-each>		

	</xsl:when>

</xsl:choose>

<root>

	<SUMMARYNODE>
		<SUMMARY>			
			<CATEGORY CATEGORYID="2">OPERATIONS PROCUREMENT</CATEGORY>
			<SUBCATEGORYID>4</SUBCATEGORYID>			
		</SUMMARY>
		
	</SUMMARYNODE>
	
	
	<SUMMARYNODE>
		<SUMMARY>			
			<CATEGORY CATEGORYID="2">XYZ</CATEGORY>
			<SUBCATEGORYID>6</SUBCATEGORYID>			
		</SUMMARY>
				
	</SUMMARYNODE>
	
	<SUMMARYNODE>
		<SUMMARY>			
			<CATEGORY CATEGORYID="5">ABC</CATEGORY>
			<SUBCATEGORYID>8</SUBCATEGORYID>			
		</SUMMARY>
			
	</SUMMARYNODE>

</root>

Open in new window

Web Languages and StandardsXML

Avatar of undefined
Last Comment
zc2
Avatar of zc2
zc2
Flag of United States of America image

you can try to insert some page generating instructions every 5 items, using the following sample:

<xsl:if test="position() mod 5 = 0">
--- new page ---
</xsl:if>
Avatar of tia_kamakshi
tia_kamakshi
Flag of United Arab Emirates image

ASKER

Thanks for your reply.

I am not that strong in xslt. Can you please help me in fixing my xslt  that how previous, next pagination will work

Thanks again
<xsl:choose>
	<xsl:when test="$type = 'open' ">

		<xsl:for-each select="//SUMMARY[CATEGORY/@CATEGORYID = $categoryID or $categoryID = 0][SUBCATEGORYID = $subCategoryID or $subCategoryID = 0][//SUMMARY/FORMATTEDDATE >= $today]">
			<xsl:sort select="//SUMMARY/FORMATTEDDATE " />
			SOME STUFF
		</xsl:for-each>		

	</xsl:when>

</xsl:choose>

Open in new window

Avatar of zc2
zc2
Flag of United States of America image

I can only give you general ideas.
Let's say we have an XML as follows:
<root>
<item>1</item>
<item>2</item>
.
.
</root>

The XSLT template could accept parameters, let's call them the "page" - for the page number (starting from 0) and the "num" - the number items on a page. A template like on the sample below will accept that params and output only the items for the specific page.
You need the "previous" and "next" commands (buttons?) to calculate the page number and pass the value to the template.



<xsl:template match="/root">
	<xsl:param name="page" select="0"/>
	<xsl:param name="num" select="6"/>
		
		<xsl:for-each select="item[position() &gt; $page * $num and position() &lt;= $page * $num + $num]">
			<xsl:value-of select="."/>,
  		</xsl:for-each>

</xsl:template>

Open in new window

Avatar of tia_kamakshi
tia_kamakshi
Flag of United Arab Emirates image

ASKER

Thanks for your reply.

Here is the xml and xslt as you advised. Please help me in fixing xslt code snippet

For this test, say I need 2 records per page.

Please advice

Thanks again
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!--end of xsl declarations-->
	<!-- global variables -->
	<!--<xsl:param name="tenderUniqueId" />-->

	<xsl:template match="/">
		<xsl:param name="page" select="0"/>
		<xsl:param name="num" select="2"/>

		<xsl:for-each select="//SUMMARY[position() &gt; $page * $num and position() &lt;= $page * $num + $num]">
			<xsl:value-of select="CATEGORY"/>
			<BR></BR>
		</xsl:for-each>

	</xsl:template>

</xsl:stylesheet>


<root>

	<SUMMARYNODE>
		<SUMMARY>
			<CATEGORY CATEGORYID="2">OPERATIONS PROCUREMENT</CATEGORY>
			<SUBCATEGORYID>4</SUBCATEGORYID>
		</SUMMARY>

	</SUMMARYNODE>


	<SUMMARYNODE>
		<SUMMARY>
			<CATEGORY CATEGORYID="2">XYZ</CATEGORY>
			<SUBCATEGORYID>6</SUBCATEGORYID>
		</SUMMARY>

	</SUMMARYNODE>

	<SUMMARYNODE>
		<SUMMARY>
			<CATEGORY CATEGORYID="5">ABC</CATEGORY>
			<SUBCATEGORYID>8</SUBCATEGORYID>
		</SUMMARY>

	</SUMMARYNODE>

	<SUMMARYNODE>
		<SUMMARY>
			<CATEGORY CATEGORYID="5">DHGFHGF</CATEGORY>
			<SUBCATEGORYID>8</SUBCATEGORYID>
		</SUMMARY>

	</SUMMARYNODE>

	<SUMMARYNODE>
		<SUMMARY>
			<CATEGORY CATEGORYID="5">JGHJLUJL H</CATEGORY>
			<SUBCATEGORYID>8</SUBCATEGORYID>
		</SUMMARY>

	</SUMMARYNODE>

</root>

Open in new window

Avatar of zc2
zc2
Flag of United States of America image

I changed the code a little to be compatible with the XML you provided.

To make the pagination work you need find a way to pass the current page number to the XSLT. It can be either stored in the XML or passed to the XSLT processor.


<xsl:param name="page" select="0"/>
<xsl:param name="num" select="2"/>

<xsl:template match="/">
	<xsl:for-each select="//SUMMARY">
		<xsl:if test="position() &gt; $page * $num and position() &lt;= $page * $num + $num">
			<xsl:value-of select="CATEGORY"/>
			<BR></BR>
  		</xsl:if>
	</xsl:for-each>
</xsl:template>

Open in new window

Avatar of tia_kamakshi
tia_kamakshi
Flag of United Arab Emirates image

ASKER

Many Thanks for providing xslt which works good when we give page no.

Now here how do we count no of pages and run loop till to print no of pages.

This will help me in doing pagination completly

Thanks again
Avatar of zc2
zc2
Flag of United States of America image

To calculate the number of the pages, you can use the following expression:
select="ceiling( count( //SUMMARY ) div $num)"

Please explain more specific, what you mean by "pagination" and how you think it should work.
Avatar of tia_kamakshi
tia_kamakshi
Flag of United Arab Emirates image

ASKER

Sorry, I was bit away from my work. I am back again. Please see attached the sample image that how I require the pagination
Please help

 User generated image
ASKER CERTIFIED SOLUTION
Avatar of zc2
zc2
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of tia_kamakshi
tia_kamakshi
Flag of United Arab Emirates image

ASKER

Many Thanks for your help. I will come back to you on this

Kind Regards
Avatar of tia_kamakshi
tia_kamakshi
Flag of United Arab Emirates image

ASKER

Many Many Thanks for your great help
Avatar of zc2
zc2
Flag of United States of America image

you're welcome
Web Languages and Standards
Web Languages and Standards

Web development can range from developing the simplest static single page of plain text to the most complex web-based internet applications, electronic businesses, and social network services using a wide variety of languages and standards, including the familiar HTML, JavaScript and jQuery, ASP and ASP.NET, PHP, ColdFusion, CSS, PHP, Flex and Flash, but also the implementation of a broad list of standards including XML, WSDL, SSDL, VoiceXML and many more.

40K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo