1 users online. Create an account or sign in to join them.Users

Search

A new XSLT utility, "URL" is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.

Get the URL of a page, according to a given ID.

Example usage:

<xsl:call-template name="url">
   <xsl:with-param name="id" select="35" />
</xsl:call-template>

I am not trying to do your work down but this utility is a perfect example for a situation when you should be using apply-templates instead of call-template.

My solution to this problem would look like

<xsl:template match="page" mode="url">
    <xsl:value-of select="concat($root,'/',@handle,'/')"/>
</xsl:template>

<xsl:template match="page/page" mode="url">
    <xsl:apply-templates select="parent::page" mode="url"/>
    <xsl:value-of select="concat(@handle,'/')"/>
</xsl:template>

you would call them using

<xsl:apply-templates select="navigation//page[@id = '35]" mode="url"/>

The problem with named templates is that they're being run without context. Think of static methods in object-oriented programming.

@kanduvisla - first off: thanks for sharing, I've come up with a utility like this a couple of times now but it's great to see a more robust one evolve.

@phoque - Thanks Nils for your recent wealth of XSLT tips (in various threads): I'm learning heaps of what you share. It seems to me you are one of the more experienced XSLT people on this forum and I would love if you'd continue sharing your tips (maybe even on your blog?).

The thing is: there's so many ways to do something with XSL, it seems, that it's difficult to improve one's 'simple' code when 'it works'. There are quite a few how-to-do-something-complex-with-xsl tips but fewer explanations of simpler concepts.

Having someone to explain to me why a certain approach is better, with code examples is immensely helpful. Thanks

@davidhund Seconded. I'm at a point in my XSLT education where I can get things working but I'm never confident that it is the best or most efficient way of going about it. Explanations like @phoque's are very helpful.

I agree, @phoque is on fire at the moment. thanks for all your help

@phoque is on fire at the moment

Yes, he's an XSLT ninja, and I also love his straight explanations. Thanks, @phoque!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.1
  • 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