Search

Let’s say I want to fill a maximum of 7 list items with … (dot groups) or numbers.

How to limit the amount of numbers and dot groups to be displayed? I have tried, but I could only manipulate the amount of numbers displayed (display number) before the dots.

There’s presently no way of doing this. In what circumstance would this be required?

In the circumstance that I have a layout in which I want to have 7 items. I have to mention that this is not exactly top priority. I simply think it looks better if the amount of items displays is constant.

The display-number governs how many page numbers are displayed. Either side there will always be a list item for Previous and a list item for Next. To always have 7 list items (assuming you have at least 7 pages), specify a display-number of 5.

The ellipses appear as children of the first or last list items.

I’ve updated to use a succinct string/replace technique.

@nick, that’s indeed a cool simplification. Works great.

I get the following error:

XSLTProcessor::transformToXml():
runtime error: file /www/htdocs/workspace/utilities/pagination.xsl line 25 element variable

XSLTProcessor::transformToXml():
xsl:variable : redefining display-number

Am I the only one with this problem?

Perhaps — I don’t get this error. Can you post the call-template used to call the pagination template?

This is my template:

<xsl:call-template name="pagination">
    <xsl:with-param name="pagination-element" select="/data/besuchen-neuigkeiten/pagination" />
    <xsl:with-param name="url" select="'/besuchen/neuigkeiten/seite/$'" />
    <xsl:with-param name="next" select="'nächste Seite'" />
    <xsl:with-param name="previous" select="'vorherige Seite'" />
</xsl:call-template>

The reason for this error seems to be the fact that $display-number is a parameter at first

<xsl:param name="display-number" />

which is then redeclared as variable a few lines below

<xsl:variable name="display-number">
    <xsl:choose>
        <xsl:when test="$display-number &lt; 3">3</xsl:when>
        <xsl:when test="$display-number &lt; $pagination-element/@total-pages">
            <xsl:value-of select="$display-number"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$pagination-element/@total-pages - 1"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

Which is normal practice — it will be received as a parameter but a variable can then redefine the name.

It could be that you’re not actually passing through the display-number. Does it work when this is set as a with-param?

Does it work when this is set as a with-param?

That works!

Nils is right. If you don’t pass the parameter, you will get an XSLT error.

Okey doke — I’ll see that this gets fixed.

OK, I’ve been playing around with this and I can’t figure out how to get it to work. Here’s my XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="../utilities/master.xsl"/>
<xsl:import href="../utilities/search-form.xsl"/>
<xsl:import href="../utilities/timeshare-listing.xsl"/>
<xsl:import href="../utilities/pagination.xsl"/>

<xsl:param name="url-minprice"/>
<xsl:param name="url-maxprice"/>
<xsl:param name="url-startweek"/>
<xsl:param name="url-endweek"/>

<xsl:template match="data">
    <h1>Listings</h1>
    <h2>Search Form</h2>
    <xsl:call-template name="search-form"/>
    <xsl:choose>
        <xsl:when test="$url-minprice!='' and $url-maxprice!=''">
            <xsl:for-each select="listings/entry">
                <xsl:variable name="price" select="price"/>
                <xsl:if test="$price &gt; $url-minprice and $url-maxprice &gt; $price or $url-minprice = $price or $url-maxprice = $price">
                    <xsl:call-template name="timeshare-listing" mode="condescend"/>
                </xsl:if>
            </xsl:for-each>
        </xsl:when>
        <xsl:when test="$url-minprice!='' and $url-maxprice=''">
            <xsl:for-each select="listings/entry">
                <xsl:variable name="price" select="price"/>
                <xsl:if test="$price &gt; $url-minprice or $url-minprice = $price">
                    <xsl:call-template name="timeshare-listing" mode="condescend"/>
                </xsl:if>
            </xsl:for-each>
        </xsl:when>
        <xsl:when test="$url-minprice='' and $url-maxprice!=''">
            <xsl:for-each select="listings/entry">
                <xsl:variable name="price" select="price"/>
                <xsl:if test="$url-maxprice &gt; $price or $url-maxprice = $price">
                    <xsl:call-template name="timeshare-listing" mode="condescend"/>
                </xsl:if>
            </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
            <ul id="timeshare-listings">
                <xsl:for-each select="listings/entry">
                    <xsl:call-template name="timeshare-listing" mode="condescend"/>
                </xsl:for-each>
            </ul>
        </xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="pagination">
        <xsl:with-param name="pagination-element" select="/data/listings/pagination" />
        <xsl:with-param name="display-number" select="'10'" />
        <xsl:with-param name="url" select="'/listings/$'" />
    </xsl:call-template>
</xsl:template>

</xsl:stylesheet>

And my XML:

<?xml version="1.0" encoding="utf-8" ?>
<data>
    <events>
        <login-info logged-in="true" id="1" user-type="developer" primary-account="yes">
            <!-- trimmed out -->
        </login-info>
    </events>
    <listings>
        <pagination total-entries="8" total-pages="2" entries-per-page="5" current-page="1" />
        <section id="13" handle="timeshare-listings">Timeshare Listings</section>
        <entry id="130">
            <!-- trimmed out, there are 8 entries in total -->
        </entry>
    </listings>
    <navigation>
        <!-- trimmed out -->
    </navigation>
    <nested-cats>
        <!-- trimmed out -->
    </nested-cats>
</data>

The latest five entries show just fine and it shows me as having two pages of results, so far so good. However, when I click on the pagination link the URL changes to “…/listings/2/” and I get a 404 error.

Now, if I go into the Admin section and go to this page’s template I can give it a URL Param of “$” and that at least gets rid of the 404 error but it still only shows the same five listings.

I have very little idea what I’m doing so any hints would be greatly appreciated.

The fix is to name page URL Parameter something like page or page-number (although page might be a reserved word — it definitely used to be so I’m not sure if this has been fixed in recent Symphony versions).

Then edit your Data Source to “Show page {$page-number} of results”.

The $ in the XSLT just represents the part of the string into which the pagination template will substitute the page number. It has no bearing on the page’s URL Parameter name itself — I could have chosen a % character or similar, but chose $ as it’s a character Symphony/XSLT developers would be familiar with.

Hope that helps you get it working.

That did it! Thanks Nick!

[edit] OK, so I may have found another small flaw. I have a number of URL parameters running after the page number but if I click any of the links I lose the URL parameters. How do I concatenate them onto the link param?

Not sure if this is a bug or I’m missing something obvious. I’ve noticed an oddity in this utility where the number of displayed items increments by one as you pass the half-way mark of the number of pages. For example if you have 15 pages worth of entries with a $display-number of 8, on pages 1-7 you’ll get:

Prev | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ... 15 | Next

While on page 8-15 you get:

Prev | 1 ... 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Next

The first set is showing 8 and the second 9. Any ideas how to fix that?

Of course as soon as I post this I work it out. To get the correct display numbers you need to change line 75 from:

<xsl:value-of select="$pagination-element/@total-pages - $display-number" />

to:

<xsl:value-of select="$pagination-element/@total-pages - $display-number + 1" />

And line 95 from:

<xsl:value-of select="$first-page + $display-number"/>

to:

<xsl:value-of select="$first-page + $display-number - 1"/>

Thanks for doing the hunting Max. I remember hitting the same or similar bug. I think it comes down to whether the display-number is odd or even. If it’s odd then it works fine because it can show an even number of pages either side of the selected page. When when it’s an even number it chokes and doesn’t perform the calculation 100% correctly.

Does your change fix for values 7, 8 and 9, or does it just fix paging when display-entries is 8?

No worries, Nick. Those two changes seem to fix the problem in all my testing—a mix of odd/even display numbers and odd/even page numbers.

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