resolve.path
Prev | Relative URI Functions | Next

## resolve.path

resolve.path — Resolve any ../ in path, except leading ../

## Description

This function resolves any relative ../ parts of a file path.

    <xsl:template name="resolve.path">
      <xsl:param name="filename" select="''"></xsl:param>
      <xsl:choose>
        <!-- Leading .. are not eliminated -->
        <xsl:when test="starts-with($filename, '../')">
          <xsl:value-of select="'../'"></xsl:value-of>
          <xsl:call-template name="resolve.path">
            <xsl:with-param name="filename" select="substring-after($filename, '../')"></xsl:with-param>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="contains($filename, '/../')">
          <xsl:call-template name="resolve.path">
            <xsl:with-param name="filename">
              <xsl:call-template name="dirname">
                <xsl:with-param name="filename" select="substring-before($filename, '/../')"></xsl:with-param>
              </xsl:call-template>
              <xsl:value-of select="substring-after($filename, '/../')"></xsl:value-of>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$filename"></xsl:value-of>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

Prev | Up | Next
trim.common.uri.paths | Home | dirname