[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Generate nested TOC from flat XHTMTL

Subject: Re: Generate nested TOC from flat XHTMTL
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 05 Sep 2006 16:52:22 -0400
generate toc xslt
Jesper,

With XSLT2.0, your best bet is to use the native grouping construct xsl:for-each-group, in particular with the group-starting-with attribute.

First, select groups of elements starting with an h1 element. Within each of these, process its first element (the h1) and then create groups starting with h2 elements. Then ... etc. As you build the ToC, you won't actually output anything for elements other than the headers themselves; but the groups will allow you to construct the necessary nesting of lists.

This can be done recursively, although you'd need in that case to parameterize the heading level of the element names and to test for a stop condition (no more headers). It's easier to build the first time if you hard-code it ... which requires you to know how many levels deep you wish your code to go (which you probably do). A further complication might arise if you don't always have "cleanly nested" heading levels (for example if you skip straight from an h1 to an h3).

Unfortunately I don't have time to demonstrate this, although maybe someone else is up to the challenge. In any case, if you look up xsl:for-each-grou/@group-starting-with that might give you some hints on how to proceed.

There are a couple of trickier methods (this is called "positional grouping") available in XSLT 1.0.

Cheers,
Wendell

At 06:58 AM 9/4/2006, you wrote:

How can I generate a TOC in correctly nested ordered XHTML list elements
from the flat heading structure in XHTML 1.0?
I am only interested in correctly nested ordered lists as output, like this:

<ol>
        <li>
                <ol>
                        <li/>
                </ol>
        </li>
        <li/>
</ol>

XSLT 2.0 will do. I have no problems with the first level.


Best regards, Jesper Tverskov

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.