This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Paging and Sorting
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Paging and Sorting
- From: "Katie McNally" <kmcnally9 at hotmail dot com>
- Date: Thu, 18 Oct 2001 15:03:31 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
I replaced the "if" statements (that tested the passed-in column parameter)
in my stylesheet with the suggested XSL:
<xsl:apply-templates select="ReturnResultSet/LoanSearchSet/Loan">
<xsl:sort select="LoanId[$column = 'LoanId'] |
LoanBorrowerSet[$column = 'LastName']
/Borrower/LastName" />
</xsl:apply-templates>
The column title links now sort the table, but there are two problems:
1)Using XML containing data for 11 loans, the Search Results page displays
loans 1 - 10 in the table. All of the data for the 11th loan is displayed
above the table. I can't determine which part of my XSL is causing this
loan data to be erroneously displayed.
The data is being displayed above the table as:
9823410-Mar-2001 New 10-Nov-1999 Max Lyons 23492 Jen Masters L 1 Josh
Masters P 2 300 S. State St. 140000.0 TRUE 7.10 13-Aug-2000
When I click the "Next Page" or "Last Page" link, the eleventh loan is
displayed in the table, and all of the data for the first ten loans is
displayed above the table.
2)When I click a column title link to sort the loans, only the 10 loans
being displayed on the page are sorted. When I click the "Next Page" link,
the eleventh loan is displayed, despite the fact that the Borrower's last
name is "Masters" and therefore the loan should have been displayed as the
fourth loan when the table is sorted by "Last Name".
Any suggestions?
Thanks,
Katie
>From: Jeni Tennison <jeni@jenitennison.com>
>Reply-To: Jeni Tennison <jeni@jenitennison.com>
>To: "Katie McNally" <kmcnally9@hotmail.com>
>CC: xsl-list@lists.mulberrytech.com
>Subject: Re: [xsl] Paging and Sorting
>Date: Thu, 18 Oct 2001 16:19:23 +0100
>
>Hi Katie,
>
> > 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.
>
>What you've got at the moment is:
>
> > <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>
>
>The reason this isn't working is that the select attribute of xsl:sort
>is evaluated relative to the nodes that are selected by the
>surrounding xsl:apply-templates/xsl:for-each. At the moment, the
>paths are looking for the 'ReturnResultSet' children of the
>'LoanSearchSet' nodes that are being sorted.
>
>I think what you actually want to do is sort the Loans against the
>LastName or LoanId, in which case you need to apply templates to the
>Loan elements, as follows:
>
> <xsl:choose>
> <xsl:when test="$column = 'LoanId'">
> <xsl:apply-templates
> select="ReturnResultSet/LoanSearchSet/Loan">
> <xsl:sort select="LoanId" />
> </xsl:apply-templates>
> </xsl:when>
> <xsl:when test="$column = 'LastName'">
> <xsl:apply-templates
> select="ReturnResultSet/LoanSearchSet/Loan">
> <xsl:sort select="LoanBorrowerSet/Borrower/LastName" />
> </xsl:apply-templates>
> </xsl:when>
> </xsl:choose>
>
>Alternatively, you could use the following trick:
>
> <xsl:apply-templates select="ReturnResultSet/LoanSearchSet/Loan">
> <xsl:sort select="LoanId[$column = 'LoanId'] |
> LoanBorrowerSet[$column = 'LastName']
> /Borrower/LastName" />
> </xsl:apply-templates>
>
>If $column is 'LastName' then the LoanId element will be selected, but
>the LoanBorrowerSet won't be, so you'll end up sorting by the value of
>the LoanId element. On the other hand, if the $column is 'LastName',
>then the LoanId element won't be selected but the
>LoanBorrowerSet/Borrower/LastName element will be, so you'll end up
>sorting by last name.
>
>Another thing I'll just mention is that you're making very strange use
>of attribute value templates. You only need to put {}s around
>expressions in attributes that you want to be evaluated dynamically
>and inserted into the attribute value. If you're adding a static
>string to the attribute value, then there's no need to use an
>attribute value template. For example, instead of:
>
> > <a
> >
>href="/loans/SearchResults.jsp?{'sort='}{$column}{'&upperLimit='}{$upperLimit}{'&action=First'}{'&counter='}{$counter}">
> > <b>First Page</b></a>
>
>You could more simply have:
>
> <a
>
>href="/loans/SearchResults.jsp?sort={$column}&upperLimit={$upperLimit}&action=First&counter={$counter}">
> <b>First Page</b></a>
>
>I hope that helps,
>
>Jeni
>
>---
>Jeni Tennison
>http://www.jenitennison.com/
>
_________________________________________________________________
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