]> granicus.if.org Git - docbook-dsssl/commitdiff
fixed bug #1528002 olinks not handling dbhtml dir
authorBob Stayton <bobs@sagehill.net>
Tue, 15 Aug 2006 08:12:47 +0000 (08:12 +0000)
committerBob Stayton <bobs@sagehill.net>
Tue, 15 Aug 2006 08:12:47 +0000 (08:12 +0000)
xsl/common/olink.xsl
xsl/common/targets.xsl
xsl/html/chunk-common.xsl

index a5e447ff2cf8ee0b00ea7e6ac272d08b626316f9..2c12e9db1b95da410e0d9e1a101dc597e8110def 100644 (file)
   </xsl:if>
 </xsl:template>
 
+<!-- Computes the href of the object containing the olink element -->
+<xsl:template name="olink.from.uri">
+  <xsl:param name="target.database"/>
+  <xsl:param name="object" select="NotAnElement"/>
+  <xsl:param name="object.targetdoc" select="$current.docid"/>
+  <xsl:param name="object.lang" 
+           select="concat($object/ancestor::*[last()]/@lang,
+                          $object/ancestor::*[last()]/@xml:lang)"/>
+
+  <xsl:variable name="parent.id">
+    <xsl:call-template name="object.id">
+      <xsl:with-param name="object" select="$object"/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <!-- Get the olink key for the parent of olink element -->
+  <xsl:variable name="from.key">
+    <xsl:call-template name="select.olink.key">
+      <xsl:with-param name="targetdoc.att" select="$object.targetdoc"/>
+      <xsl:with-param name="targetptr.att" select="$parent.id"/>
+      <xsl:with-param name="olink.lang" select="$object.lang"/>
+      <xsl:with-param name="target.database" select="$target.database"/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <xsl:variable name="from.olink.href">
+    <xsl:for-each select="$target.database" >
+      <xsl:value-of select="key('targetptr-key', $from.key)/@href" />
+    </xsl:for-each>
+  </xsl:variable>
+
+  <xsl:choose>
+    <!-- we found the olink object -->
+    <xsl:when test="$from.olink.href != ''">
+      <xsl:value-of select="$from.olink.href"/>
+    </xsl:when>
+    <xsl:when test="not($object/parent::*)">
+      <xsl:value-of select="$from.olink.href"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <!-- recurse upward in current document -->
+      <xsl:call-template name="olink.from.uri">
+        <xsl:with-param name="target.database" select="$target.database"/>
+        <xsl:with-param name="object" select="$object/parent::*"/>
+        <xsl:with-param name="object.targetdoc" select="$object.targetdoc"/>
+        <xsl:with-param name="object.lang" select="$object.lang"/>
+      </xsl:call-template>
+    </xsl:otherwise>
+  </xsl:choose>
+
+</xsl:template>
+
 <xsl:template name="olink.hottext">
   <xsl:param name="target.database"/>
   <xsl:param name="olink.lang" select="''"/>
index 91e0818280209a591051fdc4b1c6441ea23b4377..e628d69cd9be43fa153e505c904c2efb4673863b 100644 (file)
@@ -86,6 +86,7 @@ document output.
   <xsl:value-of select="$olink.base.uri"/>
   <xsl:call-template name="href.target">
     <xsl:with-param name="object" select="$nd"/>
+    <xsl:with-param name="context" select="NOTANODE"/>
   </xsl:call-template>
 </xsl:template>
 
index 31228db6e6a52ff407e3c6ff4508e1bf5ae0c48c..4a5152b8db271b605299c0268c967ec88bd7d8b6 100644 (file)
   <xsl:value-of select="$href"/>
 </xsl:template>
 
+<!-- Returns the complete olink href value if found -->
+<!-- Must take into account any dbhtml dir of the chunk containing the olink -->
+<xsl:template name="make.olink.href">
+  <xsl:param name="olink.key" select="''"/>
+  <xsl:param name="target.database"/>
+
+  <xsl:if test="$olink.key != ''">
+    <xsl:variable name="target.href" >
+      <xsl:for-each select="$target.database" >
+        <xsl:value-of select="key('targetptr-key', $olink.key)/@href" />
+      </xsl:for-each>
+    </xsl:variable>
+  
+    <!-- an olink starting point may be in a subdirectory, so need
+         the "from" reference point to compute a relative path -->
+
+    <xsl:variable name="from.href">
+      <xsl:call-template name="olink.from.uri">
+        <xsl:with-param name="target.database" select="$target.database"/>
+        <xsl:with-param name="object" select="."/>
+        <xsl:with-param name="object.targetdoc" select="$current.docid"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <!-- If the from.href has directory path, then must "../" upward
+         to document level -->
+    <xsl:variable name="upward.from.path">
+      <xsl:call-template name="upward.path">
+        <xsl:with-param name="path" select="$from.href"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:variable name="targetdoc">
+      <xsl:value-of select="substring-before($olink.key, '/')"/>
+    </xsl:variable>
+  
+    <!-- Does the target database use a sitemap? -->
+    <xsl:variable name="use.sitemap">
+      <xsl:choose>
+        <xsl:when test="$target.database//sitemap">1</xsl:when>
+        <xsl:otherwise>0</xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+  
+  
+    <!-- Get the baseuri for this targetptr -->
+    <xsl:variable name="baseuri" >
+      <xsl:choose>
+        <!-- Does the database use a sitemap? -->
+        <xsl:when test="$use.sitemap != 0" >
+          <xsl:choose>
+            <!-- Was current.docid parameter set? -->
+            <xsl:when test="$current.docid != ''">
+              <!-- Was it found in the database? -->
+              <xsl:variable name="currentdoc.key" >
+                <xsl:for-each select="$target.database" >
+                  <xsl:value-of select="key('targetdoc-key',
+                                        $current.docid)/@targetdoc" />
+                </xsl:for-each>
+              </xsl:variable>
+              <xsl:choose>
+                <xsl:when test="$currentdoc.key != ''">
+                  <xsl:for-each select="$target.database" >
+                    <xsl:call-template name="targetpath" >
+                      <xsl:with-param name="dirnode" 
+                          select="key('targetdoc-key', $current.docid)/parent::dir"/>
+                      <xsl:with-param name="targetdoc" select="$targetdoc"/>
+                    </xsl:call-template>
+                  </xsl:for-each >
+                </xsl:when>
+                <xsl:otherwise>
+                  <xsl:message>
+                    <xsl:text>Olink error: cannot compute relative </xsl:text>
+                    <xsl:text>sitemap path because $current.docid '</xsl:text>
+                    <xsl:value-of select="$current.docid"/>
+                    <xsl:text>' not found in target database.</xsl:text>
+                  </xsl:message>
+                </xsl:otherwise>
+              </xsl:choose>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:message>
+                <xsl:text>Olink warning: cannot compute relative </xsl:text>
+                <xsl:text>sitemap path without $current.docid parameter</xsl:text>
+              </xsl:message>
+            </xsl:otherwise>
+          </xsl:choose> 
+          <!-- In either case, add baseuri from its document entry-->
+          <xsl:variable name="docbaseuri">
+            <xsl:for-each select="$target.database" >
+              <xsl:value-of select="key('targetdoc-key', $targetdoc)/@baseuri" />
+            </xsl:for-each>
+          </xsl:variable>
+          <xsl:if test="$docbaseuri != ''" >
+            <xsl:value-of select="$docbaseuri"/>
+          </xsl:if>
+        </xsl:when>
+        <!-- No database sitemap in use -->
+        <xsl:otherwise>
+          <!-- Just use any baseuri from its document entry -->
+          <xsl:variable name="docbaseuri">
+            <xsl:for-each select="$target.database" >
+              <xsl:value-of select="key('targetdoc-key', $targetdoc)/@baseuri" />
+            </xsl:for-each>
+          </xsl:variable>
+          <xsl:if test="$docbaseuri != ''" >
+            <xsl:value-of select="$docbaseuri"/>
+          </xsl:if>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+  
+    <!-- Form the href information -->
+    <xsl:if test="not(contains($baseuri, ':'))">
+      <!-- if not an absolute uri, add upward path from olink chunk -->
+      <xsl:value-of select="$upward.from.path"/>
+    </xsl:if>
+
+    <xsl:if test="$baseuri != ''">
+      <xsl:value-of select="$baseuri"/>
+      <xsl:if test="substring($target.href,1,1) != '#'">
+        <!--xsl:text>/</xsl:text-->
+      </xsl:if>
+    </xsl:if>
+    <!-- optionally turn off frag for PDF references -->
+    <xsl:if test="not($insert.olink.pdf.frag = 0 and
+          translate(substring($baseuri, string-length($baseuri) - 3),
+                    'PDF', 'pdf') = '.pdf'
+          and starts-with($target.href, '#') )">
+      <xsl:value-of select="$target.href"/>
+    </xsl:if>
+  </xsl:if>
+</xsl:template>
+
+<!-- Computes "../" to reach top -->
+<xsl:template name="upward.path">
+  <xsl:param name="path" select="''"/>
+  <xsl:choose> 
+    <!-- Don't bother with absolute uris -->
+    <xsl:when test="contains($path, ':')"/>
+    <xsl:when test="starts-with($path, '/')"/>
+    <xsl:when test="contains($path, '/')">
+      <xsl:text>../</xsl:text>
+      <xsl:call-template name="upward.path">
+        <xsl:with-param name="path" select="substring-after($path, '/')"/>
+      </xsl:call-template>
+    </xsl:when>
+  </xsl:choose>
+
+</xsl:template>
+
 <!-- ==================================================================== -->
 
 <xsl:template name="html.head">