aboutsummaryrefslogtreecommitdiffstats
path: root/stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/chunk-common.xsl
diff options
context:
space:
mode:
Diffstat (limited to 'stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/chunk-common.xsl')
-rw-r--r--stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/chunk-common.xsl134
1 files changed, 116 insertions, 18 deletions
diff --git a/stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/chunk-common.xsl b/stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/chunk-common.xsl
index cfd057fe4..f452b4414 100644
--- a/stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/chunk-common.xsl
+++ b/stylesheets/lfs-xsl/docbook-xsl-snapshot/xhtml/chunk-common.xsl
@@ -737,32 +737,98 @@
<xsl:template name="href.target">
<xsl:param name="context" select="."/>
<xsl:param name="object" select="."/>
-
+ <xsl:param name="toc-context" select="."/>
+ <!-- * If $toc-context contains some node other than the current node, -->
+ <!-- * it means we're processing a link in a TOC. In that case, to -->
+ <!-- * ensure the link will work correctly, we need to take a look at -->
+ <!-- * where the file containing the TOC will get written, and where -->
+ <!-- * the file that's being linked to will get written. -->
+ <xsl:variable name="toc-output-dir">
+ <xsl:if test="not($toc-context = .)">
+ <!-- * Get the $toc-context node and all its ancestors, look down -->
+ <!-- * through them to find the last/closest node to the -->
+ <!-- * toc-context node that has a "dbhtml dir" PI, and get the -->
+ <!-- * directory name from that. That's the name of the directory -->
+ <!-- * to which the current toc output file will get written. -->
+ <xsl:call-template name="dbhtml-dir">
+ <xsl:with-param name="context" select="$toc-context/ancestor-or-self::*[processing-instruction('dbhtml')[contains(.,'dir')]][last()]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:variable>
+ <xsl:variable name="linked-file-output-dir">
+ <xsl:if test="not($toc-context = .)">
+ <!-- * Get the current node and all its ancestors, look down -->
+ <!-- * through them to find the last/closest node to the current -->
+ <!-- * node that has a "dbhtml dir" PI, and get the directory name -->
+ <!-- * from that. That's the name of the directory to which the -->
+ <!-- * file that's being linked to will get written. -->
+ <xsl:call-template name="dbhtml-dir">
+ <xsl:with-param name="context" select="ancestor-or-self::*[processing-instruction('dbhtml')[contains(.,'dir')]][last()]"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:variable>
<xsl:variable name="href.to.uri">
<xsl:call-template name="href.target.uri">
<xsl:with-param name="object" select="$object"/>
</xsl:call-template>
</xsl:variable>
-
<xsl:variable name="href.from.uri">
<xsl:call-template name="href.target.uri">
<xsl:with-param name="object" select="$context"/>
</xsl:call-template>
</xsl:variable>
-
- <!--
- <xsl:message>href.to.uri: <xsl:value-of select="$href.to.uri"/></xsl:message>
- <xsl:message>href.from.uri: <xsl:value-of select="$href.from.uri"/></xsl:message>
- -->
-
+ <!-- * <xsl:message>toc-context: <xsl:value-of select="local-name($toc-context)"/></xsl:message> -->
+ <!-- * <xsl:message>node: <xsl:value-of select="local-name(.)"/></xsl:message> -->
+ <!-- * <xsl:message>context: <xsl:value-of select="local-name($context)"/></xsl:message> -->
+ <!-- * <xsl:message>object: <xsl:value-of select="local-name($object)"/></xsl:message> -->
+ <!-- * <xsl:message>toc-output-dir: <xsl:value-of select="$toc-output-dir"/></xsl:message> -->
+ <!-- * <xsl:message>linked-file-output-dir: <xsl:value-of select="$linked-file-output-dir"/></xsl:message> -->
+ <!-- * <xsl:message>href.to.uri: <xsl:value-of select="$href.to.uri"/></xsl:message> -->
+ <!-- * <xsl:message>href.from.uri: <xsl:value-of select="$href.from.uri"/></xsl:message> -->
<xsl:variable name="href.to">
- <xsl:call-template name="trim.common.uri.paths">
- <xsl:with-param name="uriA" select="$href.to.uri"/>
- <xsl:with-param name="uriB" select="$href.from.uri"/>
- <xsl:with-param name="return" select="'A'"/>
- </xsl:call-template>
+ <xsl:choose>
+ <!-- * 2007-07-19, MikeSmith: Added the following conditional to -->
+ <!-- * deal with a problem case for links in TOCs. It checks to see -->
+ <!-- * if the output dir that a TOC will get written to is -->
+ <!-- * different from the output dir of the file being linked to. -->
+ <!-- * If it is different, we do not call trim.common.uri.paths. -->
+ <!-- * -->
+ <!-- * Reason why I added that conditional is: I ran into a bug for -->
+ <!-- * this case: -->
+ <!-- * -->
+ <!-- * 1. we are chunking into separate dirs -->
+ <!-- * -->
+ <!-- * 2. output for the TOC is written to current dir, but the file -->
+ <!-- * being linked to is written to some subdir "foo". -->
+ <!-- * -->
+ <!-- * For that case, links to that file in that TOC did not show -->
+ <!-- * the correct path - they omitted the "foo". -->
+ <!-- * -->
+ <!-- * The cause of that problem was that the trim.common.uri.paths -->
+ <!-- * template[1] was being called under all conditions. But it's -->
+ <!-- * apparent that we don't want to call trim.common.uri.paths in -->
+ <!-- * the case where a linked file is being written to a different -->
+ <!-- * directory than the TOC that contains the link, because doing -->
+ <!-- * so will cause a necessary (not redundant) directory-name -->
+ <!-- * part of the link to get inadvertently trimmed, resulting in -->
+ <!-- * a broken link to that file. Thus, added the conditional. -->
+ <!-- * -->
+ <!-- * [1] The purpose of the trim.common.uri.paths template is to -->
+ <!-- * prevent cases where, if we didn't call it, we end up with -->
+ <!-- * unnecessary, redundant directory names getting output; for -->
+ <!-- * example, "foo/foo/refname.html". -->
+ <xsl:when test="not($toc-output-dir = $linked-file-output-dir)">
+ <xsl:value-of select="$href.to.uri"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="trim.common.uri.paths">
+ <xsl:with-param name="uriA" select="$href.to.uri"/>
+ <xsl:with-param name="uriB" select="$href.from.uri"/>
+ <xsl:with-param name="return" select="'A'"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:variable>
-
<xsl:variable name="href.from">
<xsl:call-template name="trim.common.uri.paths">
<xsl:with-param name="uriA" select="$href.to.uri"/>
@@ -770,13 +836,11 @@
<xsl:with-param name="return" select="'B'"/>
</xsl:call-template>
</xsl:variable>
-
<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="'../'"/>
@@ -784,7 +848,6 @@
</xsl:call-template>
<xsl:value-of select="$href.to"/>
</xsl:variable>
-
<!--
<xsl:message>
<xsl:text>In </xsl:text>
@@ -799,7 +862,6 @@
<xsl:value-of select="$href"/>
</xsl:message>
-->
-
<xsl:value-of select="$href"/>
</xsl:template>
@@ -1444,4 +1506,40 @@
</xsl:call-template>
</xsl:template>
+<!-- ==================================================================== -->
+
+<xsl:template name="dbhtml-dir">
+ <xsl:param name="context" select="."/>
+ <!-- directories are now inherited from previous levels -->
+ <xsl:variable name="ppath">
+ <xsl:if test="$context/parent::*">
+ <xsl:call-template name="dbhtml-dir">
+ <xsl:with-param name="context" select="$context/parent::*"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:variable>
+ <xsl:variable name="path">
+ <xsl:call-template name="pi.dbhtml_dir">
+ <xsl:with-param name="node" select="$context"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="$path = ''">
+ <xsl:if test="$ppath != ''">
+ <xsl:value-of select="$ppath"/>
+ </xsl:if>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="$ppath != ''">
+ <xsl:value-of select="$ppath"/>
+ <xsl:if test="substring($ppath, string-length($ppath), 1) != '/'">
+ <xsl:text>/</xsl:text>
+ </xsl:if>
+ </xsl:if>
+ <xsl:value-of select="$path"/>
+ <xsl:text>/</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
</xsl:stylesheet>