Subject: Re: [xsl] Paging and Sorting From: "Katie McNally" <kmcnally9@xxxxxxxxxxx> Date: Thu, 18 Oct 2001 15:03:31 -0500 |
<xsl:apply-templates select="ReturnResultSet/LoanSearchSet/Loan"> <xsl:sort select="LoanId[$column = 'LoanId'] | LoanBorrowerSet[$column = 'LastName'] /Borrower/LastName" /> </xsl:apply-templates>
Thanks, Katie
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Reply-To: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> To: "Katie McNally" <kmcnally9@xxxxxxxxxxx> CC: xsl-list@xxxxxxxxxxxxxxxxxxxxxx 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Paging and Sorting, Michael Kay | Thread | Re: [xsl] Paging and Sorting, Mark Nahabedian |
Re: [xsl] Counting nodes, Jörg Heinicke | Date | [xsl] value for href, Scott Hofmann |
Month |