forrest-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ross Gardler <rgard...@apache.org>
Subject Re: Navigation links
Date Fri, 08 Oct 2004 12:36:04 GMT
Johannes Schaefer wrote:
> Dmitri Pissarenko wrote:
> 
>> Hello!
>>
>> I have about 50 text files, which are chapters of a larger text.
>>
>> I want to create a website, on which each of these texts is shown in a 
>> separate HTML file
>>
>> and in each of these files there are navigation buttons (links to next 
>> and previous
>>
>> chapter).
>>
>> I want to create those navigation links automatically.
>>
>> Is there an (easy) way to do it in Apache Forrest?
>>
>> Thanks in advance
>>
>> dap
> 
> 
> I would be very interested in "back|next", too.
> We have a solution for a link "back to top", if you're
> interested ...

Forrest cannot currently do this by default so I've copied this to the 
dev list since there is a partial solution below:

I have a skin that does this (actually I broke the "back" section, but 
next works, back used to work, I just haven't had time to fix it).

This is another of a long line of things that I have been trying to find 
the time to tidy up and commit to Forrest. If you know XSL then you 
could have a go at making my partial solution work properly and I'll put 
it into Forrest (with a property to make it optional of course).

Here is the relevant XSL code from site2xhtml.xsl:

<!-- creates links to the next and previous files as dictated by the 
menu -->
   <xsl:template name="navigationLinks">
     <xsl:if test="not($config/navigation/next/@enabled = 'false')">
         <span class="navigation">
           <xsl:for-each select="//div[@class='menu']//span[@class='sel']">

             <!-- Preceding Link -->
             <!-- FIXME: this is broken
             <xsl:variable name="dirname">
               <xsl:call-template name="dirname">
                 <xsl:with-param name="path" select="ancestor::a[4]/@href"/>
               </xsl:call-template>
             </xsl:variable>
             <xsl:variable name="filename">
               <xsl:call-template name="filename">
                 <xsl:with-param name="path" select="./a/@href"/>
               </xsl:call-template>
             </xsl:variable>
             <xsl:variable name="linkText">
               <xsl:value-of select="../preceding-sibling::*"/>
             </xsl:variable>
             <a  class="dida">
               <xsl:attribute name="href">../<xsl:value-of 
select="$dirname"/>/<xsl:value-of select="$filename"/></xsl:attribute>
               <img class="skin" src="{$skin-img-dir}/previous.gif" 
alt="Previous:"/>
               <xsl:value-of select="$linkText"/>
             </a>
             <img class="spacer" src="{$spacer}" alt="" width="10" 
height="8" />-->

             <!-- Following Link -->
             <xsl:choose>
               <xsl:when test="../following-sibling::*">
                 <xsl:variable name="linkText">
                   <xsl:value-of select="../following-sibling::*"/>
                 </xsl:variable>
                 <xsl:variable name="dirname">
                   <xsl:call-template name="dirname">
                     <xsl:with-param name="path" 
select="../following-sibling::*/a/@href"/>
                   </xsl:call-template>
                 </xsl:variable>
                 <xsl:variable name="filename">
                   <xsl:call-template name="filename">
                     <xsl:with-param name="path" 
select="../following-sibling::*/a/@href"/>
                   </xsl:call-template>
                 </xsl:variable>
                 <a class="dida">
                   <xsl:attribute name="href"><xsl:value-of 
select="$dirname"/><xsl:value-of select="$filename"/></xsl:attribute>
                   <img class="skin" src="{$skin-img-dir}/next.gif" 
alt="Next:"/>
                   <xsl:value-of select="$linkText"/>
                 </a>
                 <img class="spacer" src="{$spacer}" alt="" width="20" 
height="8" />
               </xsl:when>
               <xsl:otherwise>
                 (Last in Section - choose a new section from the menu)
               </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
         </span>
     </xsl:if>
   </xsl:template>

Just call this template to generate the link(s) in the relevant location 
on your document.

Ross

Mime
View raw message