Search

I’ve got a question for the XSLT experts:

I think we all know the problem when we’re apply-templateing without having a template that matches the direct descendant of the context: All the other, non-matched stuff will be returned as well.

This can be prevented by using “Null Templates” such as

<xsl:template match="*">
    <xsl:apply-templates />
</xsl:template>

<xsl:template match="text()" />

Is this considered good or bad practice?

Generally speaking, empty template is a very useful technique in a lot of situations. However, whether or not it is warranted depends on how you are using it.

For example if you find that more nodes are being matched by the default template than your matching templates, then consider adding a selector:

<xsl:template match="*">
    <xsl:apply-templates select="*[pagination/@total-entries &gt; 3]"/>
</xsl:template>

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