[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Paging and Sorting

Subject: RE: Paging and Sorting
From: "Katie McNally" <kmcnally9@xxxxxxxxxxx>
Date: Thu, 18 Oct 2001 08:47:20 -0500
jsp paging sorting
I created the XSL below to transform XML to HTML for a Search Results page. On the Search Results page, the user must be able to sort each of the columns in the table of loans displayed, as well as page between results (10 loans are displayed on each page). The column title links as well as the paging links ("First Page", "Previous Page", "Next Page" and "Last Page") pass a query string that contains the column title that the table is being sorted by, the current upper limit, the action (link clicked) and the overall count of loans returned in the XSML. The logic in the servlet determines which link was clicked and and what the new upper and lower limits should be (which determines which set of 10 loans should be displayed). The name of the column that the table should be sorted by, the new lower limit and the new upper limit get passed to the XSL stylesheet as parameters.

I have the paging functionality working, but not the sorting. What do I need to do to do to include sorting cababilities when the user clicks on a column link? My XSL and XML are below.

XSL:

<?xml version='1.0'?>
<!-- File loanSearchResults.xsl-->
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>


<xsl:param name="column">
</xsl:param>
<xsl:param name="lowerLimit" select="1">
</xsl:param>
<xsl:param name="upperLimit" select="10">
</xsl:param>

<xsl:template match='/'>

<xsl:variable name="counter">
<xsl:value-of select="count(ReturnResultSet/LoanSearchSet/Loan)"/>
</xsl:variable>

<table>

<tr>

<td>
<a href="/loans/SearchResults.jsp?{'sort=LoanId&amp;upperLimit=10&amp;action=None'}{'&amp;counter='}{$counter}"><b>Loan Number</b></a>
</td>


<td>

<a href="/loans/SearchResults.jsp?{'sort=LastName&amp;upperLimit=10&amp;action=None'}{'&amp;counter='}{$counter}"><b>Name</b></a>
</td>


</tr>

<xsl:if test="$column='LoanId'">
<xsl:apply-templates select="ReturnResultSet/LoanSearchSet">
<xsl:sort select="ReturnResultSet/LoanSearchSet/Loan/LoanId" order="ascending"/>
</xsl:apply-templates>
</xsl:if>


<xsl:if test="$column='LastName'">
<xsl:apply-templates select="ReturnResultSet/LoanSearchSet">
<xsl:sort select="ReturnResultSet/LoanSearchSet/Loan/LoanBorrowerSet/Borrower/LastName" order="ascending"/>
</xsl:apply-templates>
</xsl:if>


</table>


<table>


<tr>

<td>
<a href="/loans/SearchResults.jsp?{'sort='}{$column}{'&amp;upperLimit='}{$upperLimit}{'&amp;action=First'}{'&amp;counter='}{$counter}"><b>First Page</b></a>
</td>


<td>
<xsl:if test="$lowerLimit &gt; 1">
<a href="/loans/SearchResults.jsp?{'sort='}{$column}{'&amp;upperLimit='}{$upperLimit}{'&amp;action=Previous'}{'&amp;counter='}{$counter}"><b>Previous Page</b></a>
</xsl:if>
</td>


<td>
<xsl:if test="$counter &gt; $upperLimit">
<a href="/loans/SearchResults.jsp?{'sort='}{$column}{'&amp;upperLimit='}{$upperLimit}{'&amp;action=Next'}{'&amp;counter='}{$counter}"><b>Next Page</b></a>
</xsl:if>
</td>


<td>

<a href="/loans/SearchResults.jsp?{'sort='}{$column}{'&amp;upperLimit='}{$upperLimit}{'&amp;action=Last'}{'&amp;counter='}{$counter}"><b>Last Page</b></a>

</td>

</tr>
</table>
</xsl:template>

<xsl:template match="ReturnResultSet/LoanSearchSet">

<xsl:apply-templates select="Loan[position() &gt;= $lowerLimit and position() &lt;= $upperLimit]"/>
</xsl:template>


<xsl:template match="Loan[position() &gt;= $lowerLimit and position() &lt;= $upperLimit]">


<tr> <td> <xsl:variable name="loanid"> <xsl:value-of select='LoanId'/> </xsl:variable> <a href="/loans/LoanSummary.jsp?{$loanid}"> <xsl:value-of select='LoanId'/> </a> </td>

 	  <td>
	  	  <xsl:for-each select='LoanBorrowerSet/Borrower'>
		  <xsl:if test=\"Rank='1'\">
		  <xsl:value-of select='LastName'/>
		  </xsl:if>
		  </xsl:for-each>
	  </td>


</tr>



</xsl:template>


</xsl:stylesheet>


XML:


<ReturnResultSet>
	<LoanSearchSet>
		<Loan>
			<LoanId>123</LoanId>
			<LoanBorrowerSet>
				<Borrower>
					<LastName>Smith</LastName>
				</Borrower>
			</LoanBorrowerSet>
		</Loan>
		<Loan>
			<LoanId>456</LoanId>
			<LoanBorrowerSet>
				<Borrower>
					<LastName>Jones</LastName>
				</Borrower>
			</LoanBorrowerSet>
		</Loan>
		<Loan>
			<LoanId>789</LoanId>
			<LoanBorrowerSet>
				<Borrower>
					<LastName>Stills</LastName>
				</Borrower>
			</LoanBorrowerSet>
		</Loan>
		...
	</LoanSearchSet>
</ReturnResultSet>




_________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.