You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Luis Gois <lu...@mail.sonet.pt> on 2001/02/01 00:40:17 UTC

Re: Clean Page XSP sample and applying multiple XSL stylesheets

Hello Donald,
I'm really apreciating your help!

I want to use the total number of rows matching my query to create an
index to each page of 20 results. Pretty much like the index you find
at e.g. altavista.com when displaying search results.

>what are you trying to do to the results in XSP?
>- donald



Re: Clean Page XSP sample and applying multiple XSL stylesheets

Posted by Donald Ball <ba...@webslingerZ.com>.
On Wed, 31 Jan 2001, Luis Gois wrote:

> I want to use the total number of rows matching my query to create an
> index to each page of 20 results. Pretty much like the index you find
> at e.g. altavista.com when displaying search results.

you can do it iteratively simply using esql:max-rows and esql:skip-rows. i
know cos i just finished writing one a few hours ago. i needed to add one
thing to the esql language for completeness sake - i proposed an
esql:more-results template which is instantiated if more rows exist after
the maximum number has been reached, so you know when to stop making
"next" links. anyway, the basic gist is:

<xsp:page
  xmlns:xsp="http://www.apache.org/1999/XSP/Core"
  xmlns:request="http://www.apache.org/1999/XSP/Request"
  xmlns:esql="http://apache.org/cocoon/SQL/v2"
  language="java"
>

<page>
  <xsp:logic>
    int max_rows = 10;
    int skip_rows = 0;
    try {
      max_rows = Integer.parseInt(<request:get-parameter name="max-rows"/>);
    } catch (Exception e) {}
    try {
      skip_rows = Integer.parseInt(<request:get-parameter name="skip-rows"/>);
    } catch (Exception e) {}
  </xsp:logic>
  <esql:connection>
    ...
    <esql:results>
      <list>
        <xsp:attribute name="max-rows"><xsp:expr>max_rows</xsp:expr></xsp:attribute>
        <xsp:logic>
          if (work_skip_rows != 0) {
            <xsp:attribute name="prev-skip-rows"><xsp:expr>work_skip_rows - work_max_rows</xsp:expr></xsp:attribute>
          }
        </xsp:logic>
        <esql:row-results>
          ...
        </esql:row-results>
        <esql:more-results>
          <xsp:attribute name="next-skip-rows"><xsp:expr>work_skip_rows + work_max_rows</xsp:expr></xsp:attribute>
        </esql:more-results>
      </list>
    </esql:results>
    ...
  </esql:connection>
</page>

</xsp:page>

then in my stylesheet somewhere i have something like this:

<xsl:if test="@prev-skip-rows">
  <a href="foo.xml?skip-rows={@prev-skip-rows}&amp;max-rows={@max-rows}">Prev</a>
</xsl:if>
<xsl:if test="@next-skip-rows">
  <a href="foo.xml?skip-rows={@next-skip-rows}&amp;max-rows={@max-rows}">Next</a>
</xsl:if>

i'm trying to figure out how to generalize this, so that it's easier to
generate pageable results, but this should get you started. it won't work
as is because the more-results support is only in my copy of the source
right now; you can work around it by just removing the more-results and
always creating the next-skip-rows attribute, regardless if it's valid or
not.

- donald