<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:param name="pagenumber" select="0" />
	<xsl:variable name="recordsPerPage" select="2" />
	<xsl:param name="mastercategoria" />

	<xsl:template match="*|@*">			
	 	<xsl:copy>
	 		<xsl:apply-templates select="@* | * | comment() | processing-instruction() | text()"/>
	 	</xsl:copy>
	</xsl:template>
	<xsl:template match="products">
			<xsl:if test="1=0">
				<h1 style="color:red;">You need to be in "replace" mode to run this!!! <a href="http://www.bayes.co.uk/xml/index.xml?/xml/utils/instalmsxml.xml">Click here</a></h1>
			</xsl:if>
			<xsl:apply-templates select="product[position() &gt;= (($pagenumber - 1) *
$recordsPerPage) and position() &lt;= ($pagenumber * $recordsPerPage)]" />
			<div class="blerb">
			<xsl:call-template name="footerPages">
				<xsl:with-param name="element" select="'product'" />
				<xsl:with-param name="pagenumber" select="$pagenumber" />
			</xsl:call-template>
			</div>
	</xsl:template>

<xsl:template match="product">
<xsl:value-of select="TDProductId" /> <br />
<xsl:value-of select="name"/> <br />
<xsl:value-of select="TDCategoryId" /> <br />
<xsl:value-of select="description"/>
<br/><br/>
</xsl:template>
	
	
	
	
	<xsl:template name="footerPages">
		<xsl:param name="element" />
		<xsl:param name="pagenumber" />
		<xsl:variable name="total" select="count(/products/product) div $recordsPerPage"/>
		<center>
		<xsl:if test="$pagenumber &gt; 1">
			<a href="?n={$pagenumber -1}&#38;cat={$mastercategoria}">Prev</a>
		</xsl:if>
		<xsl:for-each select="*[name() = $element and position() &lt;= $total]">
			
<xsl:choose>
<xsl:when test="not(count(preceding-sibling::*) +1= $pagenumber)">
&#160;<a href="?n={count(preceding-sibling::*)+1}&#38;cat={$mastercategoria}">
<xsl:value-of select="count(preceding-sibling::*) +1" /></a>
</xsl:when>
<xsl:otherwise>
&#160;<xsl:value-of select="count(preceding-sibling::*) +1" />
</xsl:otherwise>
</xsl:choose>
		</xsl:for-each>
		<xsl:if test="$pagenumber &lt; $total">
			&#160;<a href="?n={$pagenumber +1}&#38;cat={$mastercategoria}">Next</a>
		</xsl:if>
		</center>
	</xsl:template>
</xsl:stylesheet>


