trim.common.uri.paths
Prev | Relative URI Functions | Next

## trim.common.uri.paths

trim.common.uri.paths — Trim common leading path components from a relative URI

## Description

This function trims common leading path components from a relative URI.

    <xsl:template name="trim.common.uri.paths">
      <xsl:param name="uriA" select="''"></xsl:param>
      <xsl:param name="uriB" select="''"></xsl:param>
      <xsl:param name="return" select="'A'"></xsl:param>

      <xsl:choose>
        <xsl:when test="contains($uriA, '/') and contains($uriB, '/')                     and substring-before($uriA, '/') = substring-before($uriB, '/')">
          <xsl:call-template name="trim.common.uri.paths">
            <xsl:with-param name="uriA" select="substring-after($uriA, '/')"></xsl:with-param>
            <xsl:with-param name="uriB" select="substring-after($uriB, '/')"></xsl:with-param>
            <xsl:with-param name="return" select="$return"></xsl:with-param>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$return = 'A'">
              <xsl:value-of select="$uriA"></xsl:value-of>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$uriB"></xsl:value-of>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

Prev | Up | Next
count.uri.path.depth | Home | Part 2. Common Template Reference