Search

Hello Symphony community,

having a bunch of experience with programming I seem to be failing to adapt to declarative thinking patterns. What I am trying to accomplish is to correctly format an unknown amount of the section type "Project", which are given to the page as XML output by the data source "ProjectPreviews".

I now face multiple problems:

  • The formatting can't be done for each entry-node, as two Project previews are supposed to be in one row
  • If there is only one Project in a row, the layout will break. To counter that, I will need to add an extra
    -element
  • Some projects have 3 optional values for a button. If they have the values, a button needs to be created, if they don't, the parsing should continue

Those are the problems I just can't seem to solve. I've created a xpathr gist with my current code and added some pseudocode to illustrate what I mean.

As far as I know looping without a for-each in XSLT can only be done by using recursion, but I somehow can't really get the grip of it. However, if the first issue is solved, the second might not be too hard anymore. The third one is another bugger. As the data source is configured to deliver the data as XML-output, there doesn't seem to be a way to check whether a variable is set like I did for the optional "view"-parameter in the gist.

I'd be very grateful for any hints and I'm also expecting to hear more than once that I have failed to get a proper grip of XSLT and that this gist is anything but declarative. ^^"

Look at this RECURSION tutorial from @Allen.

If I understand the problem correctly, I'm not sure Allen's recursion tutorial is going to be any help here.

I believe the majority of your concerns can be resolved by utilizing <xsl:apply-templates />. Are you familiar with <xsl:apply-templates />?

bzerangue wrote: Look at this RECURSION tutorial from @Allen.

Thanks! I watched both the linked video and the one on apply-templates now.

Lewis wrote: [...] I believe the majority of your concerns can be resolved by utilizing . [...]

Apparently yes, some of them atleast. I've stumbled upon apply-templates before, but didn't thought it would make that much of a difference. Thanks for freeing me of that misconception. Now I've switched to apply-templates for most of my processing.

alpacaaa wrote: Have fun.

Dang, that's some helluva XPath expression you got there. But it works well and smooth and seems to be the best and most elegant way to do what I want to achieve. Next time I need to do something more complicated I delve deeper into XPath first. Thanks you!

bauhouse wrote: There is also Nick Dunn's article: [...]

That's the closest XSLT syntax to a for-loop in procedural programming languages I've seen yet and might come in handy later on, thanks for sharing that little gem. ^^

Well, I'm back again with another problem, but as it's related, I figured a new thread would be a waste.

I am now trying to use the aforementioned iterator template to create a proper pagination, but I am failing to get the output right. This paste contains the relevant current code, and aside from the call-template it works as it's supposed to. But somehow, it ends up simply displaying the current-page variable in every iteration. Also, it seems like it never even reaches the "render-pagination-component"-template, as I can set it to output whatever I want, I end up not seeing any of it.

What I suspect is that there is a problem with the EXSLT-embedding, but it seems like I've done it right. I've packed the iterator code in a utility named iterator.xsl and included it like I did with others.

Should anyone know what's going on and what I've done wrong, I'd be more than happy if he could point it out in a reply. Thanks in advance.

I'd say KISS and use Datasource Pagination utility.

Aaand thanks, that works like a charm. That's a different approach than what I had in my mind, but it's more dynamic. Then I'll prepare for the launch of the site. ^-^

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