Search

I have this 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/dagboek-article.xsl"/>

<xsl:param name="total_articles" select="data/dagboek/pagination/@total-entries" />

<xsl:param name="articles_per_page">
    <xsl:choose>
        <xsl:when test="$page = 1 and $year = 2005 and $month = 04">1</xsl:when>
        <xsl:when test="$page = 1 and $year = 2005 and $month = 07">2</xsl:when>
        <xsl:when test="$page &gt;= 1 and $page &lt;= 4 and $year = 2005 and $month= 09">1</xsl:when>
        <xsl:when test="$page &gt;= 5 and $page &lt;= 7 and $year = 2005 and $month= 09">2</xsl:when>
        <xsl:when test="$page = 1 and $year = 2006 and $month=07">2</xsl:when>
        <xsl:when test="$page &gt; 7 and $year = 2005 and $month = 09">3</xsl:when>
        <xsl:when test="$year = 2007 and $month=06">1</xsl:when>
        <xsl:otherwise>4</xsl:otherwise>
    </xsl:choose>
</xsl:param>

<xsl:param name="number_pages">
    <xsl:choose>
        <xsl:when test="$year = 2005 and $month = 04">3</xsl:when>
        <xsl:when test="$year = 2005 and $month = 08">4</xsl:when>
        <xsl:when test="$year = 2005 and $month = 09">11</xsl:when>
        <xsl:when test="$year = 2006 and $month = 07">2</xsl:when>
        <xsl:otherwise>
           <xsl:value-of select="ceiling($total_articles div $articles_per_page)" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:param>

<xsl:param name="offset">
    <xsl:choose>
        <xsl:when test="$page = 1 and $year = 2005 and $month = 04">0</xsl:when>
        <xsl:when test="$page &gt; 1 and $year = 2005 and $month= 04"> <xsl:value-of select="($page - 1)* $articles_per_page - 3" /> </xsl:when>
        <xsl:when test="$page &gt; 1 and $year = 2005 and $month= 08"> <xsl:value-of select="($page - 1)* $articles_per_page - 2" /> </xsl:when>
        <xsl:when test="$page &gt;= 1 and $page &lt;= 4 and $year = 2005 and $month= 09"> <xsl:value-of select = "$page -1" /> </xsl:when>
         <xsl:when test="$page &gt;= 5 and $page &lt;= 7 and $year = 2005 and $month= 09"> <xsl:value-of select = "($page -1)* $articles_per_page - 4" /> </xsl:when>
         <xsl:when test="$page &gt; 7  and $year=2005 and $month = 09"> <xsl:value-of select = "($page -1)* $articles_per_page - 13" /> </xsl:when>
           <xsl:when test="$page = 1 and $year = 2006 and $month = 07">0</xsl:when>
            <xsl:when test="$page = 2 and $year = 2006 and $month = 07">2</xsl:when>
        <xsl:otherwise>
           <xsl:value-of select="$articles_per_page * $page  - $articles_per_page " />
        </xsl:otherwise>
    </xsl:choose>
</xsl:param>

<xsl:param name="end" select="$offset + $articles_per_page + 1" />

<xsl:template match="data">
<xsl:if test="$page &lt;= $number_pages" >
       <xsl:apply-templates select="dagboek/entry[position() &gt; $offset and position() &lt; $end]
 " />
</xsl:if>
<xsl:if test="$page &gt; $number_pages">
   <xsl:call-template name="error" />
</xsl:if>

<xsl:if test="$number_pages &gt; 1">
   <div class="post-nav">
          <xsl:if test=" $page &gt; 1" >
               <span class="previous"><a href="{$root}/dagboek/{$year}/{$month}/{$page - 1}"></a>

          </span>
          </xsl:if>
        <xsl:if test="$page &lt; $number_pages" > 
           <span class="next"><a href="{$root}/dagboek/{$year}/{$month}/{$page + 1}"></a></span>
        </xsl:if>
</div>
</xsl:if>


</xsl:template>


</xsl:stylesheet>

But now I wonder if I can achieve the same with only the use of DS.

  • total_articles is the number of articles of a month.
  • articles_per_page are the number of articles on a page.
  • number_pages are the total number of pages of a month.
  • offset is the first article of a page.
  • end is the last articles of a page.

With these parameter I can achieve that I can decide how many articles there are on a page.

No one who is willing to think with me if this is possible with a DS or a custom DS ?

To be honest I still don't understand what you're trying to achieve. I don't understand why you have so many dates hard coded in your XSLT. This immediately flags to me that you're taking the wrong approach.

What I try to achieve is that I can decide on a particular month and page how many articles are displayed. So as a example When it's april 2005 and im on page 1 then I would display 1 article. On the rest of the pages of april 2005 I would display the normal number of articles which is 4.

You can see this idea working on http://test.tamarawobben.nl

But if you have a better approach to this problem Im happy to listen. For me it's not the right approach to make a excerpt of the articles and link it to the whole article. Other approaches are welcome.

To me it looks like you'd be forced to change the template every single month in the coming years. That's definitely not the right way to do it: You should seek a way to save that information in a way that makes it accessible to editors who don't know XSLT.

Put that data in a section and find a way to automate the display of your articles depending on the settings set in that "how do I display certain months" section.

@phoque

Which data do I have to put in a section? I don't understand the way to trying to explain to me. Can you give me a example what you are meean?

You are right. For every month which don't fit into the 4 articles a page I have to change the template.

You are right. For every month which don't fit into the 4 articles a page I have to change the template.

Create a separate section that contains exacty those months. Then fetch that data using a second DS and make the XSLT adopt the output markup according to both that new data and your list of articles.

So if I understand you right I have to make a section with a text area containng the months for which I have to change the template. But what if the first page does not fit and the rest of the pages of that months does fit.

I wouldn't pick a textarea but rather the date field.

Although I have the feeling we still don't really understand what you're trying to do after all. You definitely need to draw some mock up pictures in order to explain what exactly you're after.

Work to do. First finding out how to make mock up pictures. Then making them.

@phoque:

Do you mean something like this

The programmatic way to do this is to group your entries by a Date field. The XML from that datasource will then be grouped by year/month/entry.

You would then iterate over the /year to build out the years and then the /months to build the links. Both the core Date field and DateTime extension provide this type of grouping.

So in short, you've overcomplicated it.

Example XML:

<year value="2012">
    <month value="02">
        <entry id="1503">
            <date time="12:19" weekday="5">2012-02-03</date>
        </entry>
        <entry id="1476">
            <date time="12:04" weekday="3">2012-02-01</date>
        </entry>
    </month>
</year>

Example XSLT:

<xsl:for-each select='year'>
    <h3>
        <xsl:value-of select='@value' />
    </h3>

    <ul>
        <xsl:for-each select='month'>
            <li class='month'>
                <a href='{$root}/news/{../@value}/{@value}/'>
                    <xsl:value-of select='@value' />
                </a>
            </li>
        </xsl:for-each>
    </ul>
</xsl:for-each>

That will iterate over the years and then show the months that have content. Without you having to update anything. Ever.

We use something similar on our work blog for the archives.

@brendo

You misunderstood the meanng of my script. The menu is made by a similar script as yours. This script takes care that on a page a number of articles is placed. So like in your workblog.

On page 1 display 4 articles On page 2 display 3 articles On page 3 display 5 articles.

Im trying to do the same except for me the month and year are also used together with the page.

Why 4 articles, 3 articles etc? Where are you getting those numbers from? Is that the number of articles for a particular year/month?

Have you tried making a datasource that will only return entries where the {$year}-{$month} match the entry's date?

I think @roelof wants to be able to explicitly set how many articles are shown on literally every page view of the articles/news section, based on:

  • Which month
  • Which page of the particular month's list of articles is shown

@brendo :

Sorry that I wa not much clear. The numbers are from your workblog.

@David :

Your are right. That's what I try to say to whole time. The only thing is that most of the months and pages will contain 4 article a page and there are some exceptions like you see on my xslt.

What I'm trying to figure out is why 3, why 4? Are they just numbers you decided on?

I try to explain. When I look at your workblog I see on page 1 4 articles, on page 2 of your workblog 3 articles and on page 3 of your workblog 5 articles. The number come from your workblog and has the value of number of displayed articles on a page.

When I look at your workblog I see on page 1 4 articles, on page 2 of your workblog 3 articles and on page 3 of your workblog 5 articles. The number come from your workblog and has the value of number of displayed articles on a page.

Sorry, that doesn't explain it to me.

Why wouldn't there be an equal number of articles on each page? Are they grouped by date? Are they displayed in a special manner that you didn't mention?

Examples like these don't help, please give us a set of rules that determine the number of articles displayed per page.

For the workblog I don't know. Then you have to ask brendo.

For my site there are very long articles. See for example http://test.tamarawobben.nl/dagboek/2005/09/2/

And some very small articles. See for example : http://test.tamarawobben.nl/dagboek/2005/03/1/

Im my opion a read more link does not fit in a site like me. I think it will fit into a blog about for example computers but not a diary site like me.

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