I noticed a few people asking for examples of XSLT pagination so I thought I'd post some example code that allows for flexible paging and sorting of child pages. It's based very much on the example at http://www.nibble.be/?p=11 which I've adapted (this version starts at page '1' rather than '0', which is more natural). It can also sort pages by date or title. If the sort field is a date then that date is displayed. There are lots of tweakable parameters. You just need to write a Macro to call it. (It's my first XSLT attempt, so be kind!).
The numberOfRecords variable may have the wrong count under some conditions I think because the node set used for the count is different to the node set in the apply-templates call.
You can select the node set into a variable:
<xsl:variable name="records" select="$currentPage/node[(@nodeTypeAlias = $nodeTypeAlias or $nodeTypeAlias = not(string(.))) and string(data [@alias='umbracoNaviHide']) != '1']"/>
Just a word of appreciation from myslf - I easily butchered your code to fulfil my strange requirements thanks to your fine commenting and flexible code.
I've implemented this pagination script on my site, and it doesn't return anything (no errors, but no content, page numbers or anything). I appreciate it's a long script, but can anyone see why it's not working? I can't figure out how it's supposed to be outputting the 'node' template as that's not called from anywhere, so perhaps that's the problem?
I don't know if it helps, but, refering to the first post, you can use a variable in the sort by wrapping it in braces, e.g. '... order="{$sortOrder}"...'
<xsl:apply-templatesselect="$currentPage/node [(@nodeTypeAlias = $nodeTypeAlias or $nodeTypeAlias = not(string(.))) and string(data [@alias='umbracoNaviHide']) != '1']"> <xsl:sortselect="@*[name()=$orderBy]"order="{$sortOrder}"data-type="text"/> </xsl:apply-templates>
I hope that that helps someone out (probably me when I google again) in the future.
Hey, sorry for bumping an old thread but I'd like to get this thing to work. :)
I get the same problem as Dan. The script doesn't generate any errors, nor any result! Does the code need any customization before it can work? My page layout look something like this:
I know this is an old thread, but the topic is still valid. I need to paginate a list of several hundred nodes. I don't see how I can use your example however since I group the items by month and year. If I just do a simple xsl:if inside my first for-each, I get nothing.
Flexible XSLT Paging and Sorting Example
I noticed a few people asking for examples of XSLT pagination so I thought I'd post some example code that allows for flexible paging and sorting of child pages. It's based very much on the example at http://www.nibble.be/?p=11 which I've adapted (this version starts at page '1' rather than '0', which is more natural). It can also sort pages by date or title. If the sort field is a date then that date is displayed. There are lots of tweakable parameters. You just need to write a Macro to call it. (It's my first XSLT attempt, so be kind!).
[code]
]>
<>
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
exclude-result-prefixes="msxml umbraco.library">
DEBUG
numberOfRecords =
recordsPerPage =
current page =
sortBy =
orderBy =
sortDirection =
[/code]
Hi Dan,
First off thanks for the great example. Only thing I dont have working is the page numbers, they are not displaying.
I haven't changed the for.loop and was just wondering if you have the page numbers showing on your pagination?
Thanks
Tom
Hi Dan
Good initiative. Please make sure that you put it in the wiki as well.
/Jan
Hi Dan,
Nice work, thanks!
A small bug: when determining the page number, the test condition:
should be (I think):
or even:
Hope this is helpful (and correct). I'll pass through others if I see them.
JT
Hi Dan,
The numberOfRecords variable may have the wrong count under some conditions I think because the node set used for the count is different to the node set in the apply-templates call.
You can select the node set into a variable:
Then use it for the count and apply:
I know this is just an example, but it's helped me out, so hopefully these fixes can help someone else.
Thanks,
JT
Hi Dan,
Just a word of appreciation from myslf - I easily butchered your code to fulfil my strange requirements thanks to your fine commenting and flexible code.
Much obliged to you sir.
I've implemented this pagination script on my site, and it doesn't return anything (no errors, but no content, page numbers or anything). I appreciate it's a long script, but can anyone see why it's not working? I can't figure out how it's supposed to be outputting the 'node' template as that's not called from anywhere, so perhaps that's the problem?
Hi,
I don't know if it helps, but, refering to the first post, you can use a variable in the sort by wrapping it in braces, e.g. '... order="{$sortOrder}"...'
I hope that that helps someone out (probably me when I google again) in the future.
Cheers
Steve
Hey, sorry for bumping an old thread but I'd like to get this thing to work. :)
I get the same problem as Dan. The script doesn't generate any errors, nor any result! Does the code need any customization before it can work? My page layout look something like this:
I'd like to list just the subpages from a specific node. Anyone care to point me in the right directions?
Cheers!
I know this is an old thread, but the topic is still valid. I need to paginate a list of several hundred nodes. I don't see how I can use your example however since I group the items by month and year. If I just do a simple xsl:if inside my first for-each, I get nothing.
is working on a reply...