Search

I have a webpage which displays entries from a datasource, with a filter parameter of {$entry}. When the filter param is empty, the page displays all entries, otherwise displays the single entry filtered by the parameter.

In the filtered section (when the webpage is showing only one entry) I have navigation links so the user can go to 'next' and 'previous' entry. At this point, my datasource is filtered to just one entry. Does anyone know how I can grab position() -1 for previous and position() + 1 from the unfiltered datasource?

Thanks in advance! Morgan

I have one way, but it's not the cleanest.

I have the same as you, but a second DS that always returns all entries, but only includes the fields that you require to build the next/previous buttons (presumably a field providing a handle).

Your XSLT can then find the entry before and after the entry with the matching entry ID of your original DS. So my example had two data sources: Photo Gallery (returns a list of all photos) and Photo Gallery Item (returns one entry filtered by a URL parameter).

<xsl:variable name="image" select="/data/photo-gallery-item/entry"/>
<xsl:variable name="next" select="/data/photo-gallery/entry[@id=$image/@id]/following-sibling::entry[1]"/>
<xsl:variable name="previous" select="/data/photo-gallery/entry[@id=$image/@id]/preceding-sibling::entry[1]"/>

<xsl:if test="$previous">
    <a href="/photo-gallery/photo/{$previous/@id}/">Previous Photo</a>
</xsl:if>

<xsl:if test="$next">
    <a href="/photo-gallery/photo/{$next/@id}/">Next Photo</a>
</xsl:if>

The caveat of this method is that the 'all' DS is pulling in a list of entries on every detail page. If you have a lot of entries, this could begin to put load onto your database. I recall Allen outlining a possible way using filters and paging, but it's a little hazy in my memory!

Nick,

Thanks again - works a treat!

One way to get mediate the load on the database is to use the built-in caching methods of the Dynamic XML datasource. It's a bit hacky but if you want some super simple DS caching it works quite well. The steps are:

  1. Create a new page for the DS you want to output, something like /cache/all-entries/
  2. Create the datasource you want to cache and attach it to the page you just created
  3. Dump the entire output of the DS into that page
  4. Setup a Dynamic XML DS and point it to the page you just created {$root}/cache/all-entries/

You could also potentially just setup a single page to be used for caching (/cache/), attach every DS you want to cache and then just output based on URL params (/cache/$action/). Would be slower to load each time you have to serve non-cache versions, but would keep things simpler.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details