mirror of
https://github.com/boostorg/boostbook.git
synced 2025-05-09 23:13:58 +00:00
check for absolute URI before updating relative URIs.
[SVN r32441]
This commit is contained in:
parent
51b1cb4bea
commit
3227dde659
@ -6,48 +6,85 @@
|
|||||||
|
|
||||||
<!-- ==================================================================== -->
|
<!-- ==================================================================== -->
|
||||||
|
|
||||||
|
<!-- Check if path is absolute
|
||||||
|
|
||||||
|
Not attempting to fully parse or validate absolute vs. relative URI.
|
||||||
|
Assumes an absolute url when $target matches the regex '^[a-zA-Z+-.]*:'
|
||||||
|
|
||||||
|
According to RFC1808, however, the colon (':') may also appear in a relative
|
||||||
|
URL. To workaround this limitation for relative links containing colons one
|
||||||
|
may use the alternatives below, instead.
|
||||||
|
|
||||||
|
For the relative URI this:that use ./this:that or this%3Athat, instead.
|
||||||
|
-->
|
||||||
|
<xsl:template name="is.absolute.uri">
|
||||||
|
<xsl:param name="uri"/>
|
||||||
|
|
||||||
|
<xsl:variable name="scheme1" select="substring-before($uri, ':')"/>
|
||||||
|
<xsl:variable name="scheme2" select="translate($scheme1, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.', '')"/>
|
||||||
|
|
||||||
|
<xsl:choose>
|
||||||
|
<xsl:when test="$scheme1 and not($scheme2)">1</xsl:when>
|
||||||
|
<xsl:otherwise>0</xsl:otherwise>
|
||||||
|
</xsl:choose>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
<xsl:template name="href.target.relative">
|
<xsl:template name="href.target.relative">
|
||||||
<xsl:param name="target"/>
|
<xsl:param name="target"/>
|
||||||
<xsl:param name="context" select="."/>
|
<xsl:param name="context" select="."/>
|
||||||
|
|
||||||
<xsl:variable name="href.to.uri" select="$target"/>
|
<xsl:variable name="isabsoluteuri">
|
||||||
<xsl:variable name="href.from.uri">
|
<xsl:call-template name="is.absolute.uri">
|
||||||
<xsl:call-template name="href.target.uri">
|
<xsl:with-param name="uri" select="$target"/>
|
||||||
<xsl:with-param name="object" select="$context"/>
|
|
||||||
</xsl:call-template>
|
</xsl:call-template>
|
||||||
</xsl:variable>
|
</xsl:variable>
|
||||||
|
|
||||||
<xsl:variable name="href.to">
|
<xsl:choose>
|
||||||
<xsl:call-template name="trim.common.uri.paths">
|
<xsl:when test="$isabsoluteuri='1'">
|
||||||
<xsl:with-param name="uriA" select="$href.to.uri"/>
|
<xsl:value-of select="$target"/>
|
||||||
<xsl:with-param name="uriB" select="$href.from.uri"/>
|
</xsl:when>
|
||||||
<xsl:with-param name="return" select="'A'"/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:variable>
|
|
||||||
|
|
||||||
<xsl:variable name="href.from">
|
<xsl:otherwise>
|
||||||
<xsl:call-template name="trim.common.uri.paths">
|
<xsl:variable name="href.to.uri" select="$target"/>
|
||||||
<xsl:with-param name="uriA" select="$href.to.uri"/>
|
<xsl:variable name="href.from.uri">
|
||||||
<xsl:with-param name="uriB" select="$href.from.uri"/>
|
<xsl:call-template name="href.target.uri">
|
||||||
<xsl:with-param name="return" select="'B'"/>
|
<xsl:with-param name="object" select="$context"/>
|
||||||
</xsl:call-template>
|
</xsl:call-template>
|
||||||
</xsl:variable>
|
</xsl:variable>
|
||||||
|
|
||||||
<xsl:variable name="depth">
|
<xsl:variable name="href.to">
|
||||||
<xsl:call-template name="count.uri.path.depth">
|
<xsl:call-template name="trim.common.uri.paths">
|
||||||
<xsl:with-param name="filename" select="$href.from"/>
|
<xsl:with-param name="uriA" select="$href.to.uri"/>
|
||||||
</xsl:call-template>
|
<xsl:with-param name="uriB" select="$href.from.uri"/>
|
||||||
</xsl:variable>
|
<xsl:with-param name="return" select="'A'"/>
|
||||||
|
</xsl:call-template>
|
||||||
|
</xsl:variable>
|
||||||
|
|
||||||
<xsl:variable name="href">
|
<xsl:variable name="href.from">
|
||||||
<xsl:call-template name="copy-string">
|
<xsl:call-template name="trim.common.uri.paths">
|
||||||
<xsl:with-param name="string" select="'../'"/>
|
<xsl:with-param name="uriA" select="$href.to.uri"/>
|
||||||
<xsl:with-param name="count" select="$depth"/>
|
<xsl:with-param name="uriB" select="$href.from.uri"/>
|
||||||
</xsl:call-template>
|
<xsl:with-param name="return" select="'B'"/>
|
||||||
<xsl:value-of select="$href.to"/>
|
</xsl:call-template>
|
||||||
</xsl:variable>
|
</xsl:variable>
|
||||||
|
|
||||||
<xsl:value-of select="$href"/>
|
<xsl:variable name="depth">
|
||||||
|
<xsl:call-template name="count.uri.path.depth">
|
||||||
|
<xsl:with-param name="filename" select="$href.from"/>
|
||||||
|
</xsl:call-template>
|
||||||
|
</xsl:variable>
|
||||||
|
|
||||||
|
<xsl:variable name="href">
|
||||||
|
<xsl:call-template name="copy-string">
|
||||||
|
<xsl:with-param name="string" select="'../'"/>
|
||||||
|
<xsl:with-param name="count" select="$depth"/>
|
||||||
|
</xsl:call-template>
|
||||||
|
<xsl:value-of select="$href.to"/>
|
||||||
|
</xsl:variable>
|
||||||
|
|
||||||
|
<xsl:value-of select="$href"/>
|
||||||
|
</xsl:otherwise>
|
||||||
|
</xsl:choose>
|
||||||
|
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user