Search

@ratdoesit: It seems like you are very fast in understanding the inner workings of XSLT. Most of us needed more time.

@michael-e: Yes, you’re right, ideally you’d leave the position predicate out of the match attribute for the xsl:template tags, making them more generic and therefore more powerful. Nice catch ;)

Thanks, Craig!

took me hours to find this post. couldn’t find anything to limit the output to 1. [1]. Any chance you guys know how to offset the next display of the DS so the “1” that I just limited will not be seen in the next section?

@dallasbpeters

Not sure I entirely understand what you’re going for, but DS pagination might do the trick. If you want your DS to only output 1 record, you can limit your DS output to 1 record per page, then use a {$param} (that you get from the page’s URL schema or the param pool) to say what page you want to output. These setting are below the filters on the DS editing page.

For instance, lets say your page is called ‘entries’ you can do

example.com/entries?page=2

then in your DS say limit to 1 entry per page, and show page {$url-page}.

or if your ‘entries’ page has a url schema of ‘the-page’:

example.com/entries/2

with a DS that says show page {$the-page}

@ashooner

I was hoping to loop through a single data set and for the first entry I would just show one large image and the title and some tags. Then right below that large image I was hoping to show the next 5 or six entries from the same section and show a thumbnail and title and then an excerpt from the entry.

Then I was hoping to offset the second loop so the first entry is not seen.

Maybe this screenshot would help. (I’m just started rollin’ with Symphony. Wordpress. So sorry if I use some WordPressie language. (wordpressie???) :)

Attachments:
loop.png

dallasbpeters: Thats actually quite easy. All you need are

<xsl:apply-templates select="xpath/to/entry[position() &lt; 7]" />

<xsl:template match="xpath/to/entry[1]" priority="1">
   Large image
</xsl:template>

<xsl:template match="xpath/to/entry">
   Small image
</xsl:template>

The apply-templates line goes where you want your images to appear in the markup. It will then apply the two templates on the first 6 entries you get from your DS. Because the first template has a higher priority it will override the second one, but only for the first image. All subsequent entries will be matched by the second template.

Edit: Does anybody know why [1] isn’t sufficient to increase the priority?

Or, because in case of equal priorities the processor will always use the last template you could put the <xsl:template match="xpath/to/entry[1]" /> below the <xsl:template match="xpath/to/entry" /> and leave out priority="1". But that could be harder to read once you’ll have to change something.

I suppose if you wanted to keep the [1] template above the other template in the source code you could add [position() &gt; 1] to the second template?

I suppose if you wanted to keep the [1] template above the other template in the source code you could add [position() &gt; 1] to the second template?

Of course but that way you’d end up having two lines for one rule wich isn’t exactly good programming style. :-)

Hmm. I was using modes. but now in the second template its still pulling the first. Have a look at this and tell me how jacked up it is.

home.xsl: <xsl:template match=&quot;data&quot;> <div id=&quot;content&quot; class=&quot;grid_20&quot;> <xsl:apply-templates select=&quot;projects/entry[1]&quot; mode=&quot;article&quot;/> <div id=&quot;projects&quot;> <xsl:apply-templates select=&quot;projects/entry&quot; mode=&quot;short&quot;/> </div> <h3 class=&quot;grid_20&quot;>From the Archives</h3> </div>

    &lt;div id=&quot;sidebar&quot; class=&quot;grid_4&quot;&gt;
        &lt;xsl:call-template name=&quot;welcome&quot;/&gt;
    &lt;/div&gt;
&lt;/xsl:template&gt;

And then the templates:

&lt;xsl:template match=&quot;entry&quot; mode=&quot;article&quot;&gt;
    &lt;div class=&quot;main_project&quot;&gt;
        &lt;div&gt;
            &lt;div id=&quot;main_image&quot;&gt;
            &lt;xsl:if test=&quot;(project-images) and (manage-images = 'Yes')&quot;&gt;
                &lt;xsl:call-template name=&quot;get-images&quot;&gt;
                    &lt;xsl:with-param name=&quot;image-entry&quot; select=&quot;project-images/item&quot;/&gt;                 
                &lt;/xsl:call-template&gt;
            &lt;/xsl:if&gt;
            &lt;/div&gt;
            &lt;h3 class=&quot;recent&quot;&gt;&lt;span&gt;Most Recent:&lt;/span&gt;&lt;a href=&quot;{$root}/projects/{project-title/@handle}&quot;&gt;&lt;xsl:value-of select=&quot;project-title&quot;/&gt;&lt;/a&gt;&lt;/h3&gt;
            &lt;p&gt;
                &lt;xsl:text&gt;In this project: &lt;/xsl:text&gt;
                &lt;xsl:for-each select=&quot;discipline/item&quot;&gt;
                    &lt;a href=&quot;{$root}/discipline/{@handle}&quot;&gt;&lt;xsl:value-of select=&quot;.&quot;/&gt;&lt;/a&gt;
                    &lt;xsl:if test=&quot;position() != last()&quot;&gt;, &lt;/xsl:if&gt;
                &lt;/xsl:for-each&gt;
            &lt;/p&gt;
        &lt;/div&gt;

    &lt;/div&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;entry&quot; mode=&quot;short&quot;&gt;
    &lt;div class=&quot;project&quot;&gt;   

        &lt;xsl:call-template name=&quot;get-thumbnail&quot;&gt;
            &lt;xsl:with-param name=&quot;thumbnail-entry&quot; select=&quot;thumbnail/item&quot;/&gt;                  
        &lt;/xsl:call-template&gt;

        &lt;h3&gt;&lt;a href=&quot;{$root}/projects/{project-title/@handle}&quot;&gt;&lt;xsl:value-of select=&quot;project-title&quot;/&gt;&lt;/a&gt;&lt;/h3&gt;


        &lt;xsl:apply-templates match=&quot;body&quot; mode=&quot;truncate&quot;&gt;
            &lt;xsl:param name=&quot;limit&quot; select=&quot;50&quot;/&gt;
            &lt;xsl:param name=&quot;suffix&quot; select=&quot;'&amp;#8594;'&quot;/&gt;
        &lt;/xsl:apply-templates&gt;

        &lt;p&gt;
            &lt;span&gt;&lt;xsl:call-template name=&quot;format-date&quot;&gt;
                &lt;xsl:with-param name=&quot;date&quot; select=&quot;date&quot;/&gt;
                &lt;xsl:with-param name=&quot;format&quot; select=&quot;'d m'&quot;/&gt;
            &lt;/xsl:call-template&gt;&lt;/span&gt;
        &lt;/p&gt;
        &lt;p&gt;
            &lt;xsl:for-each select=&quot;discipline/item&quot;&gt;
                &lt;a href=&quot;{$root}/discipline/{@handle}&quot;&gt;&lt;xsl:value-of select=&quot;.&quot;/&gt;&lt;/a&gt;
                &lt;xsl:if test=&quot;position() != last()&quot;&gt;, &lt;/xsl:if&gt;
            &lt;/xsl:for-each&gt;
        &lt;/p&gt;
    &lt;/div&gt;
&lt;/xsl:template&gt;

By the way, thanks a million for the help. Don’t soak up too much of your time. ;)

well that didn’t work. http://pastie.org/788661

You have to do it like this: http://pastie.org/788673

By the way, entry[x] is just a shorthand for entry[position() = x].

Cool. Thanks a ton!

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