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

Re: [xsl] Paging and Sorting


Subject: Re: [xsl] Paging and Sorting
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sat, 20 Oct 2001 14:59:33 +0100

Hi Katie,

> I want to be able to display 10 loans per page, allow the user to
> page between the returned loans, and sort the loans in the table by
> clicking on the column titles.
>
> As I mentioned in my last email, when I click the column titles,
> sorting only occurs for the 10 loans listed on the page (and not all
> the loans returned).
>
> Also, the loans that are not being displayed in the table of 10
> loans are displayed as text above the table.

I think that the reason for this is because you took my advice about
how to do the sorting, which has messed up the paging. In the
following:

> <xsl:apply-templates select="ReturnResultSet/LoanSearchSet/Loan">
>   <xsl:sort select="LoanId[$column = 'LoanId'] |
>                     LoanBorrowerSet[$column = 'LastName']/Borrower/LastName" />
> </xsl:apply-templates>

You are applying templates to *all* the Loan elements, sorting them by
whatever $column tells you to sort by. Some of these Loan elements are
caught by the following template:

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

(Although whatever process you're using has got a bug in it if it
allows you to use this template without complaining - you shouldn't
have variable references in the match attribute of xsl:template.)

The only Loan elements that are captured by this template are those
whose position is between the lower and upper limit. If a Loan element
isn't one of these select through, then it processed by the built-in
templates. The built-in templates emit all the text under an element,
so you get the content of all the Loan elements that haven't got the
required position. The reason this text is appearing above the table
is to do with a strange feature of your browser which means that text
in a table but not in a row gets displayed above a table.

So, instead you need a template that matches *all* the Loan elements.
Inside the template, you can test the position of the Loan element to
see whether it's one that you should display. Simply move the
predicate from the match pattern to an xsl:if, as follows:

<xsl:template match="Loan">
  <xsl:if test="position() >= $lowerLimit and
                position() &lt;= $upperLimit">
    <tr>
      ...
    </tr>
  </xsl:if>
</xsl:template>

Oh, and get rid of the template that's currently matching the
LoanSearchSet element - it isn't being used at all. And change the
attributes where you're still putting strings in attribute value
templates when you don't need to, e.g.:

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

should be:

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

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



Current Thread