Skip to content

Instantly share code, notes, and snippets.

@andrewminton
Created March 22, 2013 14:14
Show Gist options
  • Save andrewminton/5221571 to your computer and use it in GitHub Desktop.
Save andrewminton/5221571 to your computer and use it in GitHub Desktop.
<data>
<url-segments>
<segment>firstlink</segment>
<segment>2ndlink</segment>
<segment>thirdlink</segment>
<segment>4thlink</segment>
<segment>?poop=4thlink</segment>
</url-segments>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:apply-templates select="//data/url-segments" mode="breadcrumb"/>
</xsl:template>
<xsl:template match="//data/url-segments" mode="breadcrumb">
<xsl:apply-templates select="segment" mode="breadcrumb"/>
</xsl:template>
<xsl:template match="segment" mode="breadcrumb">
<xsl:param name="base-url" select="'/'"/>
<xsl:param name="this-segment-url" select="concat($base-url, ., '/')" />
<xsl:variable name="url">
<xsl:for-each select="preceding-sibling::*"><xsl:value-of select="."/><xsl:text>/</xsl:text></xsl:for-each>
<xsl:value-of select="."/>
</xsl:variable>
<a><xsl:attribute name="href"><xsl:value-of select="$url"/></xsl:attribute><xsl:value-of select="." /></a>
<xsl:apply-templates select="segment" mode="breadcrumb">
<xsl:with-param name="base-url" select="$this-segment-url" />
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment