|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: 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&upperLimit=10&action=None'}{'&counter='}{$counter}"><b>Loan Number</b></a> </td> <td> <a href="/loans/SearchResults.jsp?{'sort=LastName&upperLimit=10&action=None'}{'&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}{'&upperLimit='}{$upperLimit}{'&action=First'}{'&counter='}{$counter}"><b>First Page</b></a> </td> <td> <xsl:if test="$lowerLimit > 1"> <a href="/loans/SearchResults.jsp?{'sort='}{$column}{'&upperLimit='}{$upperLimit}{'&action=Previous'}{'&counter='}{$counter}"><b>Previous Page</b></a> </xsl:if> </td> <td> <xsl:if test="$counter > $upperLimit"> <a href="/loans/SearchResults.jsp?{'sort='}{$column}{'&upperLimit='}{$upperLimit}{'&action=Next'}{'&counter='}{$counter}"><b>Next Page</b></a> </xsl:if> </td> <td> <a href="/loans/SearchResults.jsp?{'sort='}{$column}{'&upperLimit='}{$upperLimit}{'&action=Last'}{'&counter='}{$counter}"><b>Last Page</b></a> </td> </tr> </table> </xsl:template> <xsl:template match="ReturnResultSet/LoanSearchSet"> <xsl:apply-templates select="Loan[position() >= $lowerLimit and position() <= $upperLimit]"/> </xsl:template> <xsl:template match="Loan[position() >= $lowerLimit and position() <= $upperLimit]">
<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>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








