[Libvir] PATCH: Autogenerate table of contents for docs

Daniel Veillard veillard at redhat.com
Wed Apr 30 14:14:58 UTC 2008

On Wed, Apr 30, 2008 at 02:05:12PM +0100, Daniel P. Berrange wrote:
> Alot of the docs pages have manually written table of contents linking to
> headings with the page. I figured this is a good candidate for being
> auto-generated.
> The basic idea is that given a document with  a series of headings
>    <h2><a name="xxx">Foo</a></h2>
>    ..
>    <h3><a name="xxx">Bar</a></h3>
>    ..
>    <h3><a name="xxx">Wizz</a></h3>
>    ..
>    <h2><a name="xxx">Oooh</a></h2>
>    ..
>    <h3><a name="xxx">Ahhh</a></h3>
> Then, generate a table of contents with a nested set of lists <ul>. THe
> XSL below attempts todo this for heading levels h2 -> h6, and splices the
> TOC into the page where it sees an <ul id='toc'></ul> element (typically
> just after <h1>).
> I'm kind of out of practice with XSL, so there's probably a nicer way
> to write the 'toc' template below...

  Yeah, it look weird but since:
   1/ the HTML is flat you can't base counting more on structure
   2/ h2/h3/h4/h5/h6 are not a real subsetting pattern you can't
      use recursion 

 one suggestion, instead of
   <a href="#{a/@name}"><xsl:value-of select="a/text()"/></a>
at each level, use something like
   <a href="#{a/@name}"><xsl:text><xsl:value-of select="string(a)"/></xsl:text></a>
to still capture text if the header is not just made of a single text node.


Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard at redhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

More information about the libvir-list mailing list