3 Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
5 Distributed under the Boost Software License, Version 1.0.
6 (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
9 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12 <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/lib/lib.xsl"/>
14 <!-- ==================================================================== -->
16 <!-- Check if path is absolute
18 Not attempting to fully parse or validate absolute vs. relative URI.
19 Assumes an absolute url when $target matches the regex '^[a-zA-Z.+-]*:'
21 According to RFC1808, however, the colon (':') may also appear in a relative
22 URL. To workaround this limitation for relative links containing colons one
23 may use the alternatives below, instead.
25 For the relative URI this:that use ./this:that or this%3Athat, instead.
27 <xsl:template name="is.absolute.uri">
28 <xsl:param name="uri"/>
30 <xsl:variable name="scheme1" select="substring-before($uri, ':')"/>
31 <xsl:variable name="scheme2" select="translate($scheme1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.', '')"/>
34 <xsl:when test="$scheme1 and not($scheme2)">1</xsl:when>
35 <xsl:otherwise>0</xsl:otherwise>
39 <xsl:template name="href.target.relative">
40 <xsl:param name="target"/>
41 <xsl:param name="context" select="."/>
43 <xsl:variable name="isabsoluteuri">
44 <xsl:call-template name="is.absolute.uri">
45 <xsl:with-param name="uri" select="$target"/>
50 <xsl:when test="$isabsoluteuri='1'">
51 <xsl:value-of select="$target"/>
55 <xsl:variable name="href.to.uri" select="$target"/>
56 <xsl:variable name="href.from.uri">
57 <xsl:call-template name="href.target.uri">
58 <xsl:with-param name="object" select="$context"/>
62 <xsl:variable name="href.to">
63 <xsl:call-template name="trim.common.uri.paths">
64 <xsl:with-param name="uriA" select="$href.to.uri"/>
65 <xsl:with-param name="uriB" select="$href.from.uri"/>
66 <xsl:with-param name="return" select="'A'"/>
70 <xsl:variable name="href.from">
71 <xsl:call-template name="trim.common.uri.paths">
72 <xsl:with-param name="uriA" select="$href.to.uri"/>
73 <xsl:with-param name="uriB" select="$href.from.uri"/>
74 <xsl:with-param name="return" select="'B'"/>
78 <xsl:variable name="depth">
79 <xsl:call-template name="count.uri.path.depth">
80 <xsl:with-param name="filename" select="$href.from"/>
84 <xsl:variable name="href">
85 <xsl:call-template name="copy-string">
86 <xsl:with-param name="string" select="'../'"/>
87 <xsl:with-param name="count" select="$depth"/>
89 <xsl:value-of select="$href.to"/>
92 <xsl:value-of select="$href"/>