Search

I am running into an issue with a second template that is called with in the first not selecting a node the way it seems it should.

<xsl:template match="data">
  <xsl:call-template name="new-template"/>
</xsl:template>

<xsl:template match="node1/node2" name="current">
  <h1><xsl:value-of select="name()"/></h1>
</xsl:template>

Instead of of returning node2 it returns date. When I call it within a xsl:for-each it does matches the node level of the for-each. Can someone enlighten me on what I am doing wrong, or what I am misunderstanding? Thanks!

Can you post some more of your XSLT, and your Data Source XML? At the moment your two templates are mutually exclusive: the first template calls a named template called new-template rather than an apply-templates selecting node1/node2.

I think you were trying to do this:

<xsl:template match="data">
  <xsl:apply-templates select="node1/node2"/>
</xsl:template>

<xsl:template match="node2">
  <h1><xsl:value-of select="."/></h1>
</xsl:template>

Although you might have to switch the arguments of select and match… I am not sure.

Thanks phoque that did the trick.

Glad I could help.

Basically, apply-templates executes a certain template (the one with the correct match) for every element you’re selecting. call-template executes a template (the one with the correct name) only once.

You can find more on apply-templates in one of Allens screencasts.

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