[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Paging and Sorting


Subject: RE: [xsl] Paging and Sorting
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Thu, 18 Oct 2001 17:18:35 +0100

You might care to look in the FAQ under sorting.

Mike Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of 
> Katie McNally
> Sent: 18 October 2001 14:47
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Paging and 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/Bor
> rower/LastName" 
> order="ascending"/>
>   	</xsl:apply-templates>
> </xsl:if>
> 
> </table>
> 
> 
> <table>
> 
> <tr>
> 
> <td>
> 	<a 
> href="/loans/SearchResults.jsp?{'sort='}{$column}{'&amp;upperL
> imit='}{$upperLimit}{'&amp;action=First'}{'&amp;counter='}{$co
> unter}"><b>First 
> Page</b></a>
> </td>
> 
> <td>
> 	<xsl:if test="$lowerLimit &gt; 1">
> 	<a 
> href="/loans/SearchResults.jsp?{'sort='}{$column}{'&amp;upperL
> imit='}{$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;upperL
> imit='}{$upperLimit}{'&amp;action=Next'}{'&amp;counter='}{$cou
> nter}"><b>Next 
> Page</b></a>
> 	</xsl:if>
> </td>
> 
> <td>
> 
> 	<a 
> href="/loans/SearchResults.jsp?{'sort='}{$column}{'&amp;upperL
> imit='}{$upperLimit}{'&amp;action=Last'}{'&amp;counter='}{$cou
> nter}"><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
> 

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



Current Thread
Keywords