Default umbraco has a bunch of xslt templates you can choose from when creating a new xslt file, for me about 80% of the time I start from a template and adjust it to my needs. But one thing that is missing is an example of paging, so for those of you who would like to know how to add paging to a list, check out the examples below. To change the number of items displayed just change the recordsPerPage variable. I started from the “list sub pages from current page template” in umbraco and added 2 examples with paging below (one with only a previous and a next link and another example that also adds page numbers).
Without paging ( List Sub Pages From Current Page template )
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp “ ”> ]>
<xsl:stylesheet
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”
exclude-result-prefixes=”msxml umbraco.library”>
<xsl:output method=”xml” omit-xml-declaration=”yes”/>
<xsl:param name=”currentPage”/>
<xsl:template match=”/”>
<!– The fun starts here –>
<ul>
<xsl:for-each select=”$currentPage/node [string(data [@alias=’umbracoNaviHide’]) != ‘1′]”>
<li>
<a href=”{umbraco.library:NiceUrl(@id)}”>
<xsl:value-of select=”@nodeName”/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
With paging ( previous + next )
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp “ ”> ]>
<xsl:stylesheet
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”
exclude-result-prefixes=”msxml umbraco.library”>
<xsl:output method=”xml” omit-xml-declaration=”yes”/>
<xsl:param name=”currentPage”/>
<xsl:template match=”/”>
<xsl:variable name=”recordsPerPage” select=”1″/>
<xsl:variable name=”pageNumber” >
<xsl:choose>
<!– first page –>
<xsl:when test=”umbraco.library:RequestQueryString(’page’) <= 0 or string(umbraco.library:RequestQueryString(’page’)) = ” or string(umbraco.library:RequestQueryString(’page’)) = ‘NaN’”>0</xsl:when>
<!– what was passed in –>
<xsl:otherwise>
<xsl:value-of select=”umbraco.library:RequestQueryString(’page’)”/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name=”numberOfRecords” select=”count($currentPage/node)”/>
<!– The fun starts here –>
<ul>
<xsl:for-each select=”$currentPage/node [string(data [@alias=’umbracoNaviHide’]) != ‘1′]”>
<xsl:if test=”position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
<li>
<a href=”{umbraco.library:NiceUrl(@id)}”>
<xsl:value-of select=”@nodeName”/>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
<xsl:if test=”$pageNumber > 0″>
<a href=”?page{$pageNumber -1}”>previous </a>
</xsl:if>
<xsl:if test=”(($pageNumber +1 ) * $recordsPerPage) < ($numberOfRecords)”>
<a href=”?page={$pageNumber +1}”>next</a>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
With paging ( previous + page numbers + next )
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp “ ”> ]>
<xsl:stylesheet
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”
exclude-result-prefixes=”msxml umbraco.library”>
<xsl:output method=”xml” omit-xml-declaration=”yes”/>
<xsl:param name=”currentPage”/>
<xsl:template match=”/”>
<xsl:variable name=”recordsPerPage” select=”1″/>
<xsl:variable name=”pageNumber” >
<xsl:choose>
<!– first page –>
<xsl:when test=”umbraco.library:RequestQueryString(’page’) <= 0 or string(umbraco.library:RequestQueryString(’page’)) = ” or string(umbraco.library:RequestQueryString(’page’)) = ‘NaN’”>0</xsl:when>
<!– what was passed in –>
<xsl:otherwise>
<xsl:value-of select=”umbraco.library:RequestQueryString(’page’)”/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name=”numberOfRecords” select=”count($currentPage/node)”/>
<!– The fun starts here –>
<ul>
<xsl:for-each select=”$currentPage/node [string(data [@alias=’umbracoNaviHide’]) != ‘1′]”>
<xsl:if test=”position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage )">
<li>
<a href=”{umbraco.library:NiceUrl(@id)}”>
<xsl:value-of select=”@nodeName”/>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
<xsl:if test=”$pageNumber > 0″>
<a href=”?page{$pageNumber -1}”>previous </a>
</xsl:if>
<xsl:call-template name=”for.loop”>
<xsl:with-param name=”i”>1</xsl:with-param>
<xsl:with-param name=”page” select=”$pageNumber +1″></xsl:with-param>
<xsl:with-param name=”count” select=”ceiling(count($currentPage/node)div $recordsPerPage)”></xsl:with-param>
</xsl:call-template>
<xsl:if test=”(($pageNumber +1 ) * $recordsPerPage) < ($numberOfRecords)”>
<a href=”?page={$pageNumber +1}”>next</a>
</xsl:if>
</xsl:template>
<xsl:template name=”for.loop”>
<xsl:param name=”i”/>
<xsl:param name=”count”/>
<xsl:param name=”page”/>
<xsl:if test=”$i <= $count”>
<xsl:if test=”$page != $i”>
<a href=”{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}” >
<xsl:value-of select=”$i” />
</a>
</xsl:if>
<xsl:if test=”$page = $i”>
<xsl:value-of select=”$i” />
</xsl:if>
</xsl:if>
<xsl:if test=”$i <= $count”>
<xsl:call-template name=”for.loop”>
<xsl:with-param name=”i”>
<xsl:value-of select=”$i + 1″/>
</xsl:with-param>
<xsl:with-param name=”count”>
<xsl:value-of select=”$count”/>
</xsl:with-param>
<xsl:with-param name=”page”>
<xsl:value-of select=”$page”/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>