1 users online. Create an account or sign in to join them.Users
Recursive Page tree traversing
This is an open discussion with no replies, filed under XSLT.
Search
Create an account or sign in to comment.
1 users online. Create an account or sign in to join them.Users
This is an open discussion with no replies, filed under XSLT.
Create an account or sign in to comment.
Symphony • Open Source XSLT CMS
--with-xsl)
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-handleand need to prefix it with it's parent's handles:/parent/sub/page-handleAnyway, 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: