I am trying to add paging to the data that I am displaying on screen, but it doesn't work. Whenever data is returned it is always the complete dataset (over 100 records, which should produce a page for every 10 records), and it always starts on page number 0. Here is my code :
XSL :
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl=" xmlns:asp="Remove">
<xslutput method="html" />
<xslaram name="discount" select="0.5" />
<xsl:template match="/">
<!--Set the paging characteristics - number of records per page, page number and record count-->
<!--Set the number of records per page-->
<xslaram name="recordsPerPage" select="504" />
<!--Page number field-->
<xslaram name="pageNumber" select="0" />
<!--Record count field-->
<xslaram name="recordCount" select="504" />
<html>
<title>XSL Transformation</title>
<body>
<h2>USER LIST</h2>
<table width="100%" height="0" cellspacing="1" cellpadding="0">
<tr bgcolor="#ff0000">
<td background="images/ListHeaderRed.jpg" width="70px">
<font size="2px" color="#ffffff" family="verdana">
<b>User Key</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="120px">
<font size="2px" color="#ffffff" family="verdana">
<b>Team Manager</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="70px">
<font size="2px" color="#ffffff" family="verdana">
<b>Team Type</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="100px">
<font size="2px" color="#ffffff" family="verdana">
<b>Territory Code</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="70px">
<font size="2px" color="#ffffff" family="verdana">
<b>User Name</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="100px">
<font size="2px" color="#ffffff" family="verdana">
<b>Numeric Value</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="140px">
<font size="2px" color="#ffffff" family="verdana">
<b>Calculation (50%)</b>
</font>
</td>
</tr>
<xsl:for-each select="row">
<xsl:sort select="@UserKey" data-type="number" />
<xsl:if test="position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage)">
<xsl:choose>
<!--Returns the index position of the node that is currently being processed
Example: //book[position()<=3]
Result: Selects the first three book elements-->
<xsl:when test="position() mod 2 = 0">
<tr bgcolor="#d3d3d3">
<td>
<xsl:value-of select="@UserKey"/>
</td>
<td>
<xsl:value-of select="@TeamManager"/>
</td>
<td>
<xsl:value-of select="@TeamType"/>
</td>
<xsl:if test="@TerritoryCode > 5000">
<td bgcolor="green">
<xsl:value-of select="@TerritoryCode"/>
</td>
</xsl:if>
<xsl:if test="@TerritoryCode < 5000">
<td bgcolor="orange">
<xsl:value-of select="@TerritoryCode"/>
</td>
</xsl:if>
<td>
<a href="UserDetails.aspx?UserKey={@UserKey}&UserName={@UserName}">
<xsl:value-of select="@UserName" />
</a>
</td>
<td>
<xsl:value-of select="@NumericExample" />
</td>
<td>
<xsl:value-of select="@NumericExample * ($discount)" />
</td>
</tr>
</xsl:when>
<xsltherwise>
<tr bgcolor="#f5f5f5">
<td>
<xsl:value-of select="@UserKey"/>
</td>
<td>
<xsl:value-of select="@TeamManager"/>
</td>
<td>
<xsl:value-of select="@TeamType"/>
</td>
<xsl:if test="@TerritoryCode > 5000">
<td bgcolor="green">
<xsl:value-of select="@TerritoryCode"/>
</td>
</xsl:if>
<xsl:if test="@TerritoryCode < 5000">
<td bgcolor="orange">
<xsl:value-of select="@TerritoryCode"/>
</td>
</xsl:if>
<td>
<a href="UserDetails.aspx?UserKey={@UserKey}&UserName={@UserName}">
<xsl:value-of select="@UserName" />
</a>
</td>
<td>
<xsl:value-of select="@NumericExample" />
</td>
<td>
<xsl:value-of select="@NumericExample * ($discount)" />
</td>
</tr>
</xsltherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</table>
<!--Start of Show previous/next page links-->
<!--Show the previous page, only if pageNumber>0 -->
<span>
<xsl:if test="$pageNumber > 0">
<xsl:element name="a">
<xsl:attribute name="href">
?pagenumber=<xsl:value-of select="number($pageNumber)-1"/>
</xsl:attribute>
<< Previous Page
</xsl:element>
       
</xsl:if>
<!--Next page, do not show when at end() of listing-->
<xsl:if test="($recordCount - ((1+number($pageNumber)) * $recordsPerPage))> 0">
<xsl:element name="a">
<xsl:attribute name="href">?pagenumber=<xsl:value-of select="number($pageNumber)+1" />
</xsl:attribute>
Next Page >>
</xsl:element>
</xsl:if>
</span>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Stored procedure :
CREATE procedure dbo.ViewUserListForXml
as
SELECT u.userKey as 'UserKey',
t.teammanager as 'TeamManager',
l.teamtype as 'TeamType',
l.teamtypeid as 'TeamTypeID',
t.teamkey as 'TeamKey',
u.territorycode as 'TerritoryCode',
u.userName as 'UserName',
u.userLogin as 'UserLogin',
u.userPassword as 'Password',
u.userEmail as 'Email',
u.region as 'Region',
u.businessunit as 'BusinessUnit',
u.lastLoginDate as 'LastLogin',
u.active as 'Active',
'100' as 'NumericExample'
FROM UserLogin u INNER JOIN
Teams t ON t.TeamKey = u.ClientSiteKey inner join
lookup_TeamTypes l on l.teamtypeid = t.TeamTypeID
ORDER BY u.UserName
For Xml raw
GO
C# :
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.Xsl;
using System.IO;
using System.Xml.XPath;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection objConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["XeroxConnectionString"].ConnectionString);
objConnection.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "ViewUserListForXml";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = objConnection;
XmlReader reader = cmd.ExecuteXmlReader();
XPathDocument xpathDoc = new XPathDocument(reader);
objConnection.Close();
XslCompiledTransform transform = new XslCompiledTransform();
string xslPath = Request.PhysicalApplicationPath + "xslViewUserList.xslt";
transform.Load(xslPath);
XsltArgumentList argsList = new XsltArgumentList();
int pageNumber = Convert.ToInt32(Request.QueryString["pagenumber"]);
argsList.AddParam("recordsPerPage", "", 10);
argsList.AddParam("pageNumber", "", pageNumber);
argsList.AddParam("recordCount", "", 504);
transform.Transform(xpathDoc, argsList, Response.Output);
}
}
Any assistance would be much appreciated, this is the first time I am using XSL so the more advanced stuff in this is proving difficult!
XSL :
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl=" xmlns:asp="Remove">
<xslutput method="html" />
<xslaram name="discount" select="0.5" />
<xsl:template match="/">
<!--Set the paging characteristics - number of records per page, page number and record count-->
<!--Set the number of records per page-->
<xslaram name="recordsPerPage" select="504" />
<!--Page number field-->
<xslaram name="pageNumber" select="0" />
<!--Record count field-->
<xslaram name="recordCount" select="504" />
<html>
<title>XSL Transformation</title>
<body>
<h2>USER LIST</h2>
<table width="100%" height="0" cellspacing="1" cellpadding="0">
<tr bgcolor="#ff0000">
<td background="images/ListHeaderRed.jpg" width="70px">
<font size="2px" color="#ffffff" family="verdana">
<b>User Key</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="120px">
<font size="2px" color="#ffffff" family="verdana">
<b>Team Manager</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="70px">
<font size="2px" color="#ffffff" family="verdana">
<b>Team Type</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="100px">
<font size="2px" color="#ffffff" family="verdana">
<b>Territory Code</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="70px">
<font size="2px" color="#ffffff" family="verdana">
<b>User Name</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="100px">
<font size="2px" color="#ffffff" family="verdana">
<b>Numeric Value</b>
</font>
</td>
<td background="images/ListHeaderRed.jpg" width="140px">
<font size="2px" color="#ffffff" family="verdana">
<b>Calculation (50%)</b>
</font>
</td>
</tr>
<xsl:for-each select="row">
<xsl:sort select="@UserKey" data-type="number" />
<xsl:if test="position() > $recordsPerPage * number($pageNumber) and
position() <= number($recordsPerPage * number($pageNumber) +
$recordsPerPage)">
<xsl:choose>
<!--Returns the index position of the node that is currently being processed
Example: //book[position()<=3]
Result: Selects the first three book elements-->
<xsl:when test="position() mod 2 = 0">
<tr bgcolor="#d3d3d3">
<td>
<xsl:value-of select="@UserKey"/>
</td>
<td>
<xsl:value-of select="@TeamManager"/>
</td>
<td>
<xsl:value-of select="@TeamType"/>
</td>
<xsl:if test="@TerritoryCode > 5000">
<td bgcolor="green">
<xsl:value-of select="@TerritoryCode"/>
</td>
</xsl:if>
<xsl:if test="@TerritoryCode < 5000">
<td bgcolor="orange">
<xsl:value-of select="@TerritoryCode"/>
</td>
</xsl:if>
<td>
<a href="UserDetails.aspx?UserKey={@UserKey}&UserName={@UserName}">
<xsl:value-of select="@UserName" />
</a>
</td>
<td>
<xsl:value-of select="@NumericExample" />
</td>
<td>
<xsl:value-of select="@NumericExample * ($discount)" />
</td>
</tr>
</xsl:when>
<xsltherwise>
<tr bgcolor="#f5f5f5">
<td>
<xsl:value-of select="@UserKey"/>
</td>
<td>
<xsl:value-of select="@TeamManager"/>
</td>
<td>
<xsl:value-of select="@TeamType"/>
</td>
<xsl:if test="@TerritoryCode > 5000">
<td bgcolor="green">
<xsl:value-of select="@TerritoryCode"/>
</td>
</xsl:if>
<xsl:if test="@TerritoryCode < 5000">
<td bgcolor="orange">
<xsl:value-of select="@TerritoryCode"/>
</td>
</xsl:if>
<td>
<a href="UserDetails.aspx?UserKey={@UserKey}&UserName={@UserName}">
<xsl:value-of select="@UserName" />
</a>
</td>
<td>
<xsl:value-of select="@NumericExample" />
</td>
<td>
<xsl:value-of select="@NumericExample * ($discount)" />
</td>
</tr>
</xsltherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</table>
<!--Start of Show previous/next page links-->
<!--Show the previous page, only if pageNumber>0 -->
<span>
<xsl:if test="$pageNumber > 0">
<xsl:element name="a">
<xsl:attribute name="href">
?pagenumber=<xsl:value-of select="number($pageNumber)-1"/>
</xsl:attribute>
<< Previous Page
</xsl:element>
       
</xsl:if>
<!--Next page, do not show when at end() of listing-->
<xsl:if test="($recordCount - ((1+number($pageNumber)) * $recordsPerPage))> 0">
<xsl:element name="a">
<xsl:attribute name="href">?pagenumber=<xsl:value-of select="number($pageNumber)+1" />
</xsl:attribute>
Next Page >>
</xsl:element>
</xsl:if>
</span>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Stored procedure :
CREATE procedure dbo.ViewUserListForXml
as
SELECT u.userKey as 'UserKey',
t.teammanager as 'TeamManager',
l.teamtype as 'TeamType',
l.teamtypeid as 'TeamTypeID',
t.teamkey as 'TeamKey',
u.territorycode as 'TerritoryCode',
u.userName as 'UserName',
u.userLogin as 'UserLogin',
u.userPassword as 'Password',
u.userEmail as 'Email',
u.region as 'Region',
u.businessunit as 'BusinessUnit',
u.lastLoginDate as 'LastLogin',
u.active as 'Active',
'100' as 'NumericExample'
FROM UserLogin u INNER JOIN
Teams t ON t.TeamKey = u.ClientSiteKey inner join
lookup_TeamTypes l on l.teamtypeid = t.TeamTypeID
ORDER BY u.UserName
For Xml raw
GO
C# :
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.Xsl;
using System.IO;
using System.Xml.XPath;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection objConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["XeroxConnectionString"].ConnectionString);
objConnection.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "ViewUserListForXml";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = objConnection;
XmlReader reader = cmd.ExecuteXmlReader();
XPathDocument xpathDoc = new XPathDocument(reader);
objConnection.Close();
XslCompiledTransform transform = new XslCompiledTransform();
string xslPath = Request.PhysicalApplicationPath + "xslViewUserList.xslt";
transform.Load(xslPath);
XsltArgumentList argsList = new XsltArgumentList();
int pageNumber = Convert.ToInt32(Request.QueryString["pagenumber"]);
argsList.AddParam("recordsPerPage", "", 10);
argsList.AddParam("pageNumber", "", pageNumber);
argsList.AddParam("recordCount", "", 504);
transform.Transform(xpathDoc, argsList, Response.Output);
}
}
Any assistance would be much appreciated, this is the first time I am using XSL so the more advanced stuff in this is proving difficult!