Search

I have this:

<xsl:template match="laatste-themadossier-berichten/entry">
  <xsl:variable name="themadossier-id" select="themadossier/item/@id" />
  <xsl:value-of select="/data/themadossiers/entry[@id=$themadossier-id]/klein/@path" />
</xsl:template>

When I replace the $themadossier-id with the select statement this won't work. Why is that? Do I really need to use that variable?

It took me a while too back then. Somebody eventually hinted me at the current() function. :-)

<xsl:template match="laatste-themadossier-berichten/entry">
    <xsl:value-of select="/data/themadossiers/entry[@id=current()/themadossier/item/@id]/klein/@path" />
</xsl:template>

Great, thanks :) Am I correct that you want to avoid variables as much as possible?

I actually like using $var when it saves a big XPATH expression, makes it much more readable. I don't think there's any huge disadvantages really, but it would not be always necessary.

Also, is ./ not a shorter alias for current()/?

Also, is ./ not a shorter alias for current()/?

Depends of context. In this case it's not the same thing. Read this.

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