Search

A new XSLT utility, “Data Source Pagination” is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.

Features

  • Previous and Next buttons
  • Configurable number of page number links to display
  • When many pages are returned, list is truncated for clarity (see image)
  • Clean HTML and classes for disabling and selecting states
  • A CSS stylesheet as an example to modify

Styled example

Template with styling

(CSS moved to Gist)

Great! Thank you, Nick!

Great! Thanks.

Awesome, thanks for that Nick, I'll be using this soon.

Sweet. Thanks, Nick.

This doesn't seem to be working for me, does this look right?

 <?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/get-article.xsl"/>
   <xsl:import href="../utilities/get-notes.xsl"/>
   <xsl:import href="../utilities/get-comments.xsl"/>
   <xsl:import href="../utilities/pagination.xsl"/>
   <xsl:import href="../utilities/string-replace.xsl"/>

   <xsl:template match="data">
    <xsl:apply-templates select="homepage-article"/>
   </xsl:template>

   <xsl:call-template name="pagination">
     <xsl:with-param name="pagination-element" select="/data/articles/pagination" />
     <xsl:with-param name="display-number" select="'7'" />
     <xsl:with-param name="url" select="'/articles-index/?p=$'" />
  </xsl:call-template>

 </xsl:stylesheet>

This doesn't seem to be working for me, does this look right?

Do you have enough entries to require pagination? Is your articles data source named "articles"?

We discovered a bug with this template earlier in the week on very large datasets. When there are more than 3000 pages of results, the template will fail because one of the templates is recursively called to write each page number, and LibXSLT has a default limit of 3000 recursions. The fix is quite simple, but I'm having trouble getting it just right; but an update will be posted soon.

But it won't affect storecky's issue. My best best is the same as Lewis', one of the following:

  • your articles data source only does not require paging (there are fewer entries than the per-page setting in your DS) therefore the paging template is not shown
  • there isn't a data source named articles attached to the page

Do you get any errors, or the paging links just won't show?

okay, what I have is my page "blog" in that page I have this source: (Updated From Before)

 <?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/get-article.xsl"/>
  <xsl:import href="../utilities/get-notes.xsl"/>
  <xsl:import href="../utilities/get-comments.xsl"/>
  <xsl:import href="../utilities/pagination.xsl"/>
  <xsl:import href="../utilities/string-replace.xsl"/>

  <xsl:template match="data">
    <xsl:apply-templates select="homepage-article"/>
   <xsl:call-template name="pagination">
      <xsl:with-param name="pagination-element" select="/data/articles/pagination" />
     <xsl:with-param name="display-number" select="'7'" />
     <xsl:with-param name="url" select="'/articles-index/?p=1'" />
  </xsl:call-template>
  </xsl:template>

</xsl:stylesheet>

My problem is that the Pagination doesn't show up on the bottom ( http://stephenkorecky.com/blog/ ) however if I try to add the Articles DS I get a 404 which is somewhat expected since I told it to display an error if nothing is there.

Maybe I have the wrong idea about this, but I on my blog page http://stephenkorecky.com/blog/ I would at the bottom like to be able to go to an earlier post. I have 6 articles, and 5 per page.

Have you included the pagination element in your data source? It would be helpful if you also posted your XML for that particular page.

Yes, my DS does have the pagination included, here is my source for the article page:

  <?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/get-article.xsl"/>
  <xsl:import href="../utilities/get-comments.xsl"/>

  <xsl:template match="data">
    <xsl:apply-templates select="articles"/>
    <!-- <hr/> -->
    <xsl:apply-templates select="comments"/>
    <!-- <hr/> -->
    <h2>Make a comment</h2>
    <div id="guideline">
      <h4>Rules</h4>
      <ul>
        <li>Just respect my blog and the people commenting. No being a jackass.</li>
        <li>Text is formatted with <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a>.</li>
      </ul>
    </div>
    <form action="" method="post">
      <xsl:for-each select="events/save-comment">
        <p class="{@result}">
          <xsl:choose>
            <xsl:when test="@result = 'success'">Your comment has been saved successfully.</xsl:when>
            <xsl:otherwise>The system encountered errors when saving your comment. Please check if all the required fields have been filled.</xsl:otherwise>
          </xsl:choose>
        </p>
      </xsl:for-each>
      <fieldset id="comment_form">
        <label>
          <xsl:text>Name </xsl:text>
          <input class="text" type="text" name="fields[author]" value="{events/save-comment/post-values/author}" />
        </label>
        <label>
          <xsl:text>Email </xsl:text>
          <input class="text" type="text" name="fields[email]" value="{events/save-comment/post-values/email}" />
        </label>
        <label>
          <xsl:text>Website </xsl:text>
          <input class="text" type="text" name="fields[website]" value="{events/save-comment/post-values/website}" />
        </label>
        <label>
          <xsl:text>Comment </xsl:text>
          <textarea name="fields[comment]" rows="5" cols="21"><xsl:value-of select="events/save-comment/post-values/comment" /></textarea>
        </label>

        <input name="fields[article]" value="{articles/entry/@id}" type="hidden" />

  <input name="akismet[author]" value="author" type="hidden" />
  <input name="akismet[email]" value="email" type="hidden" />
  <input name="akismet[url]" value="website" type="hidden" />

        <input id="submit" type="submit" name="action[save-comment]" value="Post Comment" />
      </fieldset>
    </form>
  </xsl:template>

  </xsl:stylesheet>

Add ?debug to the end of the page's URL on the front-end and post the XML.

Here you go, thanks for looking into this!

<?xml version="1.0" encoding="utf-8" ?>
<data>
    <events>
        <login-info logged-in="true" id="1" user-type="developer" primary-account="yes">
            <name>Stephen Korecky</name>
            <username>skorecky</username>
            <email>skorecky@gmail.com</email>
            <default-section id="6" handle="articles">Articles</default-section>
        </login-info>
    </events>
    <comments>
        <section id="9" handle="comments">Comments</section>
        <error>No Records Found.</error>
    </comments>
    <homepage-article>
        <section id="6" handle="articles">Articles</section>
        <pagination total-entries="7" total-pages="2" entries-per-page="5" current-page="1" />
        <entry id="137" comments="0" images="0">
            <title handle="gits-trailing-whitespace">Git's Trailing Whitespace</title>
            <body word-count="160"><p>This is a recent problem I have come across with Git. Now I love using Git, but this put a damper on my workflow since the white space isn&#8217;t causing any problem, and aren&#8217;t even visible in my text editor. When you get the error, you may see something like this.</p>
<pre><code>*
* You have some suspicious patch lines:
*
* In mint/pepper/shauninman/iphone/class.php
* trailing whitespace (line 125)
</code></pre>
<p>If you come across this problem, it will happen on a commit and won&#8217;t let you commit or push your project. You will have to edit .git/hooks/pre-commit Toward the bottom you will find this</p>
<pre><code>if (/s$/) {
  bad_line("trailing whitespace", $_);
}
if (/^s* t/) {
  bad_line("indent SP followed by a TAB", $_);
}
</code></pre>
<p>Just comment those lines out like so.</p>
<pre><code># if (/s$/) {
#   bad_line("trailing whitespace", $_);
# }
# if (/^s* t/) {
#   bad_line("indent SP followed by a TAB", $_);
# }
</code></pre>
<p>After you do that, you should no longer have an issue. Just be sure to check your files locally to make sure everything is working alright.</p></body>
            <date time="10:40" weekday="5">2009-01-23</date>
        </entry>
    </homepage-article>
    <navigation>
        <page handle="home">
            <name>Home</name>
            <types>
                <type>index</type>
            </types>
        </page>
        <page handle="blog">
            <name>Blog</name>
        </page>
        <page handle="about">
            <name>About</name>
        </page>
        <page handle="contact">
            <name>Contact</name>
        </page>
        <page handle="articles">
            <name>Articles</name>
            <types>
                <type>hidden</type>
            </types>
        </page>
        <page handle="archive">
            <name>Archive</name>
            <types>
                <type>hidden</type>
            </types>
        </page>
        <page handle="drafts">
            <name>Drafts</name>
            <types>
                <type>admin</type>
            </types>
        </page>
        <page handle="rss">
            <name>RSS</name>
            <types>
                <type>hidden</type>
                <type>XML</type>
            </types>
        </page>
        <page handle="maintenance">
            <name>Maintenance</name>
            <types>
                <type>hidden</type>
                <type>maintenance</type>
            </types>
        </page>
        <page handle="404-page-not-found">
            <name>404: Page Not Found</name>
            <types>
                <type>404</type>
                <type>hidden</type>
            </types>
        </page>
    </navigation>
    <website-owner>
        <author id="1" user-type="developer" primary-account="yes">
            <username>skorecky</username>
            <name>Stephen Korecky</name>
        </author>
    </website-owner>
    <article-images>
        <section id="10" handle="images">Images</section>
        <error>No Records Found.</error>
    </article-images>
</data>

Doesn't look like you have the articles data-source attached to the page.

Hi, I am new to symphony

should this always work - http://www.url.com/articles/?p=2

for me it doesn't work, so I put 'p' in the URL parameters

changed this: <xsl:with-param name="url" select="'/articles-index/?p=$'" />

to this: <xsl:with-param name="url" select="'/articles-index/$'" />

and now everything is ok, but what can be the reason that this ?p=1 doesn't work?

Because if you don't pass 'p' as a page URL param but rather as a GET param, it can't be accessed with $p but rather with $url-p. So...

If it's a page URL param called p:

something.com/page/foo gives you $p = "foo"

whereas

something.com/page?p=foo gives you $url-p = "foo"

thanks, now it works

I have one more question

I filter my articles by categories so when I go to a given category the url is

articles/category

the pagination works - for example this works articles/category/2

but in the pagination links it doesn't know that right now I am in a category

so can I change this to show fulll url including category that I'm currently in?

<xsl:with-param name="url" select="'/articles/$'"/>

to something like this:

<xsl:with-param name="url" select="'/articles/category/$'"/>

??

Depending on how you can get the category name itself, the value of the URL can be concatenated:

<xsl:with-param name="url" select="concat('/articles/', $category-name, '/$')"/>

This will concatenate a string with your category name in the middle; making the assumption that $category-name is a URL parameter on your articles page.

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