I need to make a dynamic XSL template call

Here is an example ..

<xsl:call-template name="concat( 'component-', @handle )" />

Is there a way to implement this dynamic call?

Sounds like you actually want to use apply-templates. :-) What is it you're after?

but I have to pass a param..

You can still do

<xsl:apply-templates select="." mode="component">
   <xsl:with-param name="meh" select="$meh" />

hmm, what is mode ?

You can tell the templating engine to only search among templates matching the selected node with a certain mode.

Take a look at the Ninja templates, all of those templates run in mode="html". If they didn't, those templates would match anything, even /data. To prevent that you switch to that mode only when you actually want to use those templates.

Thanks! I searched all over the internet and nobody actually says what mode is.

I did :-)

You can tell the templating engine to only search among templates matching the selected node with a certain mode.

Basically the following

<xsl:apply-templates select="entry" mode="yeah"/>
<xsl:apply-templates select="entry" />

<xsl:template match="entry">

<xsl:template match="entry" mode="yeah">

Will output

Hello World

A perfect realworld example are the Ninja Utilities. They make sure you don't accidentally start them by forcing you to use mode="html" when you're sure you want to start them.

The utility itself makes sure to never switch to anything but mode="html" by always using it in all template matchs and apply-templates.


I've been trying to figure out how to use the same matched data twice to output e.g. a set of names and bios down the centre of a page, then reuse just the names in a side column for navigation.

Are modes the right solution for something like this? Is there another solution?

I'm very new to this XSL game, so you might have to dumb it down for me.

Thanks, D

Modes are a perfect match for this. Here is what you could do, basically:

<xsl:apply-templates select="data">
    <xsl:apply-templates select="my-data" mode="content"/>
    <xsl:apply-templates select="my-data" mode="nav-sidebar"/>

<xsl:template match="my-data" mode="content">

<xsl:template match="my-data" mode="nav-sidebar">

You might think about better names for the modes. In my example they are "presentation-related". You might prefer names like list, brief and full.

Magic! Thanks very much.


You are welcome! (The world of XSLT is full of magic.)

OK – if I use modes in the above example, then want to click through to an individual view page which would contain just one name and bio in the centre column, but still had all names in the navigation side column, how should I achieve this?

To make the centre column, I think I'd create another data source which only outputs one entry filtered by the name; would I also have to create a further data source which would output all names (without bios) to serve the navigation column's purpose?


You might try and do it with a single Datausource, but on the long run (if you change/add functionality later) it is much better to use two DSs. So it's "good practice".

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