Search

I want to check if a template has already been defined, is that possible?

(The template itself is entered in the page template, but it is optional, so I need to check if it exists to prevent xslt errors..)

No, its not possible. Although it sounds like a problem that could be solved with an empty template and the import hierachy.

It would be really helpful if you could tell us what exactly you’re trying to do.

You can also set priority to templates , so you could for example give your optional template priority = 1 and it will supersede (i.e. replace) a template with the same match value that is being processed at the same time, but does not have a priority assigned (or has a lower one) .

You can also set priority to templates , so you could for example give your optional template priority = 1 and it will supersede (i.e. replace) a template with the same match value that is being processed at the same time, but does not have a priority assigned (or has a lower one) .

Thanks! That was exactly what I needed!

It’s important to note that priority are also given to more specific pattern matches.

For example,

data/articles/entry[@comments > 2]

has higher priority than

data/articles/entry

Also, explicitly setting priority, will trump ones without.

XSLT rule matching is very similar to CSS.

Thanks Allen!

The only problem I have right now is these templates do not match anything, they just output stuff (js & css headers to be precise). Right now, I call them using <xsl:call-template name="css-template" />, the priority setting here causes the compiler to throw errors..

Is there any way to set priority using named templates?

You might want to try switching to apply-templates using a mode. Something like:

<xsl:apply-templates select="data" mode="css" />

Then I think you can have templates like:

<xsl:template match="data" mode="css">
    <p>Template one</p>
</xsl:template>

And

<xsl:template match="data" mode="css" priority="1">
    <p>Overriding template</p>
</xsl:template>

Could you paste your XSL somewhere so we can take a closer look?

There’s a good article describing how priority and modes etc works in XSLT; How XSLT Works by Evan Lenz.

There you’ll also find a table with all the default priority values for different matching patterns.

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