Search

As I am learning XSLT/Symphony I’ve noticed that there’s almost always various ways of doing the same thing.

That’s wonderful, but obviously I’d like to learn the best/most efficient ways ;-)

Some documentation on (general) XSL best practices would be of help.

I’ve got two particular questions:

  • When dealing with a ‘set’ of results (entries/items) I can use a xsl:for-each loop or use a xsl:template. A template seems more elegant, allowing more flexibility. But are there any other pointers as to what method to choose? (e.g. Performance?)
  • What seems to be the best way of ‘including snippets’? I don’t necessarily mean separate XSL template (as in utilities) but maybe simply some global HTML.

At the moment I use a xsl:import with a ‘utility’ that merely contains some HTML (no xslt functionality. Are there other, better, ways of including snippets of recurring HTML?

Templates/For-each: I’d go for templates. They’re leaner, you can do recursion with a single finger snap and use the full potential of overloading templates.
The size of your XML isn’t nearly large enough for the performance-difference to have any impact.

What exactly do you mean by “global HTML”? <html />, <body />, your menu etc.? Have a look at the template structure in the default workspace (page.xsl imports master.xsl), it’s very similar to what I end up doing all the time.

@Phogue thanks.

I figured templates are probably the more elegant solution. Thanks for reinforcing that notion ;)

As for ‘snippets’: I totally get the master.xsl vs. page.xsl importing. What I was looking for was something like <xsl:include> for ‘static’ snippets: this might be the site’s footer or contact info, or anything (not necessarily xsl templates but static HTML).

<xsl:include> seems not appropriate since it is a top-level element, I cannot use it in another xsl template. This is why I am currently using <xsl:import> in combination with <xsl:call-template>.

You can wrap that static HTML in a <xsl:template name="footer" /> and call it using <xsl:call-template name="footer" />.

Right. I would need to <xsl:import> it before I can call it, correct?

Correct.

Bear in mind a key difference between xsl:include and xsl:import is that the rules in imported stylesheets will be overridden by matching rules of equal priority in the importing stylesheet.

includeed stylesheets, on the other hand, are basically treated as though their rules were part of the includeing stylesheet, which can lead to conflicts between matching rules of equal priority.

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