Search

Alright, I have two questions.

QUESTION 1

So I have a book review section where I list my Book reviews. I have managed to group them by date. I now want to group them by year and then month so it looks like this:

JAN 2010
 - entry 1
 - entry 2
 - etc.

FEB 2010
 - entry 1
 - entry 2
 - etc.

Right now, it displayed and grouped by day

2010-06-05
 - entry
 - entry

2010-06-28
 - entry
 - entry

My XML @ pastie.org/1024279

And my XSLT @ pastie.org/1024260

How would I go about formatting it the way I want?

Question 2

I have my book reviews sorted by rating. My XSLT is @ pastie.org/1024277

and

<xsl:template name="book-review-by-list">
<xsl:for-each select="homepage-book-reviews/entry">

<xsl:if test="rating = 3">

<dd>
            <dl>
              <dt>
                <div class="dl-ar-books">‎</div>
              </dt>
                <dd><a href="{$root}/reviews/movies/{title/@handle}/" class="movies"><xsl:value-of select="title"/></a> &#160;&#160;(<xsl:value-of select="release-year"/>)

<br/>
<xsl:copy-of select="synopsis" /> 

</dd> 
</dl>
</dd>
</xsl:if>

</xsl:for-each>
</xsl:template>

Now I want to display each entry sorted by its rating

1 STAR
-entry
-entry 2

2 STAR
-entry
-entry 2

3 STAR
-entry
-entry 2

The template above is set to rating = 3. Is there a more efficient way to list my book reviews instead of creating a separate template for each rating?

Edited for formtting.

Q1

You should be able to “group by” > publish date. This will be in the data source editing screen, in the lower right, immediately under XML Output. This will create year and month elements in which your entries will will be placed.

Q2

The ‘correct’, xslt purist way i believe would be to use a keys and muenchian grouping.

I have solved the rating problem using the muenchian method.

But I can’t still figure how to sort by year/month instead of year/month/day in Q1 using the meunchian method.

Not sure if it will fully address your problem, but you could look at using multiple xsl:sort elements like so:

<xsl:sort select="substring(published-date, 1, 4)" data-type="number" order="ascending"/>
<xsl:sort select="substring(published-date, 6, 2)" data-type="number" order="ascending"/>

This should save you having to break down further.

Thats what I was looking for! Instead of using xsl:sort, I used substring(publish-date, 1, 7) and plugged that right into the muenchian sort. So it looks like this

xsl:key name="linklog-by-date" match="homepage-book-reviews/entry" use="substring(publish-date, 1, 7)"

and

for-each select="homepage-book-reviews/entry[count(. | key('linklog-by-date', substring(publish-date, 1, 7))[1]) = 1]"

and

<xsl:for-each select="key('linklog-by-date', substring(publish-date, 1, 7))">

The numbers 1,7 refer to how many numbers you use to sort by. Let this be a reference to someone who may have the same problem in the future.

I have another question, though. How can I show X amount of entries depending on the page? For example, I want to show 5 book review entries on the homepage, and on the archive page I want to show all the book review entries without pagination and on another page I only want to show 7. In my book review datasource I changed the default to Show a maximum of {$book-review-entries} results. But now what? What Do I do now?

You’re going to need to use three data sources there, one for each page, and use the limit number.

I’m pretty sure there is way to do it without three separate datasources. Thats what I am trying to avoid. If I set a parameter, how would I define it in each page so that it displays differently in each page?

I’m pretty sure I saw it done before somewhere, but I forgot.

You’ll could write the XSL manually and artificially restrict the shown entries to the number you want. If you don’t need pagination, this will work just fine - although you’ll want to tune your existing data sources to return only the maximum number of entries you might need at any given time.

You’ll could write the XSL manually and artificially restrict the shown entries to the number you want. If you don’t need pagination, this will work just fine

I was thinking alone these lines but i’m not sure where to start. Would I use xsl:param name="book-review-entry-limit">3</xsl:param on each page?

Yeah, something like that. Best practice would be to make the limit a param or variable at the top of your template, and then you can adjust it as you see fit.

Then you could say something like:

<xsl:for-each select="entry[position() &lt; $book-review-entry-limit]">
    …
</xsl:for-each>

That’s off the top of my head and untested. Obviously you could do something similar using templates as well, but xsl:for-each tends to be faster in most cases.

I keep getting a “division by zero” error when I try both xsl:param name="book-review-entry-limit">3</xsl:param and xsl:variable name="book-review-entry-limit">5</xsl:variable

$entries['total-pages'] = max(1, ceil($entries['total-entries'] * (1 / $entriesPerPage)));

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