| 1 | <?xml version="1.0"?> |
|---|
| 2 | <!-- |
|---|
| 3 | Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com> |
|---|
| 4 | |
|---|
| 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) |
|---|
| 8 | --> |
|---|
| 9 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|---|
| 10 | version="1.0"> |
|---|
| 11 | |
|---|
| 12 | <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/lib/lib.xsl"/> |
|---|
| 13 | |
|---|
| 14 | <!-- ==================================================================== --> |
|---|
| 15 | |
|---|
| 16 | <!-- Check if path is absolute |
|---|
| 17 | |
|---|
| 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.+-]*:' |
|---|
| 20 | |
|---|
| 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. |
|---|
| 24 | |
|---|
| 25 | For the relative URI this:that use ./this:that or this%3Athat, instead. |
|---|
| 26 | --> |
|---|
| 27 | <xsl:template name="is.absolute.uri"> |
|---|
| 28 | <xsl:param name="uri"/> |
|---|
| 29 | |
|---|
| 30 | <xsl:variable name="scheme1" select="substring-before($uri, ':')"/> |
|---|
| 31 | <xsl:variable name="scheme2" select="translate($scheme1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.', '')"/> |
|---|
| 32 | |
|---|
| 33 | <xsl:choose> |
|---|
| 34 | <xsl:when test="$scheme1 and not($scheme2)">1</xsl:when> |
|---|
| 35 | <xsl:otherwise>0</xsl:otherwise> |
|---|
| 36 | </xsl:choose> |
|---|
| 37 | </xsl:template> |
|---|
| 38 | |
|---|
| 39 | <xsl:template name="href.target.relative"> |
|---|
| 40 | <xsl:param name="target"/> |
|---|
| 41 | <xsl:param name="context" select="."/> |
|---|
| 42 | |
|---|
| 43 | <xsl:variable name="isabsoluteuri"> |
|---|
| 44 | <xsl:call-template name="is.absolute.uri"> |
|---|
| 45 | <xsl:with-param name="uri" select="$target"/> |
|---|
| 46 | </xsl:call-template> |
|---|
| 47 | </xsl:variable> |
|---|
| 48 | |
|---|
| 49 | <xsl:choose> |
|---|
| 50 | <xsl:when test="$isabsoluteuri='1'"> |
|---|
| 51 | <xsl:value-of select="$target"/> |
|---|
| 52 | </xsl:when> |
|---|
| 53 | |
|---|
| 54 | <xsl:otherwise> |
|---|
| 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"/> |
|---|
| 59 | </xsl:call-template> |
|---|
| 60 | </xsl:variable> |
|---|
| 61 | |
|---|
| 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'"/> |
|---|
| 67 | </xsl:call-template> |
|---|
| 68 | </xsl:variable> |
|---|
| 69 | |
|---|
| 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'"/> |
|---|
| 75 | </xsl:call-template> |
|---|
| 76 | </xsl:variable> |
|---|
| 77 | |
|---|
| 78 | <xsl:variable name="depth"> |
|---|
| 79 | <xsl:call-template name="count.uri.path.depth"> |
|---|
| 80 | <xsl:with-param name="filename" select="$href.from"/> |
|---|
| 81 | </xsl:call-template> |
|---|
| 82 | </xsl:variable> |
|---|
| 83 | |
|---|
| 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"/> |
|---|
| 88 | </xsl:call-template> |
|---|
| 89 | <xsl:value-of select="$href.to"/> |
|---|
| 90 | </xsl:variable> |
|---|
| 91 | |
|---|
| 92 | <xsl:value-of select="$href"/> |
|---|
| 93 | </xsl:otherwise> |
|---|
| 94 | </xsl:choose> |
|---|
| 95 | |
|---|
| 96 | </xsl:template> |
|---|
| 97 | |
|---|
| 98 | </xsl:stylesheet> |
|---|