Search

What's the best practice for referring to different templates using 'apply templates'

normal practice is <xsl:apply-templates select="data/generalds/entry/years/item"/>
and the tempate:
<xsl:template match="years/item">content</xsl:template>

No i'd like to refer to the same node with different content:
<xsl:template match="years/item">different content</xsl:template>

What is the best approach? Or do i have to use 'template name' ?

Add the mode attribute to apply-templates. It's like naming a function.

For normal practice:

<xsl:apply-templates select="data/generalds/entry/years/item" mode="normal_practice" />

<xsl:template match="years/item" mode="normal_practice">
    content
</xsl:template>

Different content:

<xsl:apply-templates select="data/generalds/entry/years/item" mode="different_content" />

<xsl:template match="years/item" mode="different_content">
    different content
</xsl:template>

Perfect!

I had seen this before somewhere on this forum, but couldn't remeber where... thank you

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