Search

Hi Guys,

I am fiddling with a little XSL snippet to create a permalink of a certain page. The use case is that I have a page (possibly nested) and need to construct the complete url (with parent-handles if any). It's like the opposite of the familiar recursive navigation: we have an endnode /page-handle and need to prefix it with it's parent's handles: /parent/sub/page-handle

Anyway, this has been discussed more than once and I know of e.g. the Breadcrumb field but I thought I'd try my hand at a little XSL.

However, I'm just starting with XSL and recursion makes my head hurt. I believe this works but could you take a look and see how it can be improved?

<xsl:template name="recursive-permalink">
  <xsl:param name="page-id"/>
  <xsl:param name="pre-slug"/>
  <xsl:param name="slug" select="concat(/data/navigation//page[@id=$page-id]/@handle, '/', $pre-slug)"/>
  <xsl:choose>
    <xsl:when test="/data/navigation//page[page[@id=$page-id]]">
      <!-- Do we have a parent page? -->
      <xsl:call-template name="recursive-permalink">
        <xsl:with-param name="page-id" select="/data/navigation//page[page[@id=$page-id]]/@id"/>
        <xsl:with-param name="pre-slug" select="$slug"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$slug"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

You would call the template as such:

<xsl:call-template name="recursive-permalink">
  <xsl:with-param name="page-id" select="current()/internal-link/page/@id"/>
</xsl:call-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