[daisy] Auto TOC for a document?
Bruno Dumon
bruno at outerthought.org
Fri Sep 14 03:21:40 CDT 2007
On Thu, 2007-09-13 at 20:09 +0200, Vincent Mouton wrote:
> >
> >
> > Hi
> > Many pages created in our Daisy site are quite big, and have multiple
> > sections. Sometimes, its a pain to search for the relevant section. Is
> > there
> > a way a TOC can be automatically included, based on the h1, h2 and h3
> > headers?
>
> Shiva,
>
> You could accomplish this through XSLT (i.e. in the skin).
>
> Pretty rough, but you could loop through all tags at the first level inside
> a part, and check for h1, h2, h3, ... tags
>
> <!-- UNTESTED -->
> <!-- This it the TOC -->
>
> <ul>
> <xsl:for-each select="d:parts/d:part[@name =
> 'PART_NAME_TO_DEFINE']/html/body/*[name() = 'h1' or name() = 'h2' or name()
> = 'h2']">
>
> <li><a href="#{name()}_{position()}"><xsl:apply-templates
> /></a></li>
>
> </xsl:for-each>
> </ul>
>
>
> <!--
> This is the actual content rendering
> You repeat this principle for all tags, to render the content, and
> when encountering a heading, add an id="" attribute to it
> -->
>
> <xsl:for-each select="d:parts/d:part[@name =
> 'PART_NAME_TO_DEFINE']/html/body/*">
> <xsl:if test="name() = 'h1' or name() = 'h2' or name() = 'h2'">
> <a id="{name()}_{position()}"></a>
> <!-- Even better would be to define the id attribute to the
> h1, h2, ... tags itself -->
> </xsl:if>
> <xsl:apply-templates />
> </xsl:for-each>
>
>
> > One possible solution was to create links to the different sections in
> > the
> > navigation menu but it could get difficult for big documents.
>
>
> I'm not sure how this would affect performance...
>
>
A problem with the XSLT approach is that it won't work with included
documents, each included document will have its own TOC while one global
TOC would be better.
I would consider implementing this client-side, in javascript. If anyone
does this, patches are of course welcome.
BTW, in the document editor, there is already such TOC functionality via
the 'goto' button on the toolbar.
--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno at outerthought.org bruno at apache.org
More information about the daisy
mailing list