count.uri.path.depth

count.uri.path.depth — Count the number of path components in a relative URI

Description

This function counts the number of path components in a relative URI.

<xsl:template name="count.uri.path.depth">
  <xsl:param name="filename" select="''"></xsl:param>
  <xsl:param name="count" select="0"></xsl:param>

  <xsl:choose>
    <xsl:when test="contains($filename, '/')">
      <xsl:call-template name="count.uri.path.depth">
        <xsl:with-param name="filename" select="substring-after($filename, '/')"></xsl:with-param>
        <xsl:with-param name="count" select="$count + 1"></xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$count"></xsl:value-of>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>