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

Recursively traversing an outline with level gaps

Subject: Recursively traversing an outline with level gaps
From: Martynas Jusevicius <martynas.jusevicius@xxxxxxxxx>
Date: Wed, 24 Mar 2010 19:51:59 +0100
 Recursively traversing an outline with level gaps
Hey list,

I want to create a nested list (ToC) from a XHTML source, which
contains @class attributes on elements.
A separate document, styles.xml, contains information about styles and
which outline level they belong to. @style:name matches @class in
XHTML.

The tricky part is, that not all styles are necessarily used in XHTML.
And if they are, the outline hierarchy is not necessarily maintained
-- for example, only styles with level 1, 3 and 5 can be used.

How would you traverse such a structure? My approach is to do it
recursively, by finding all styles for the current level, and all
elements of these styles (simplified):

<xsl:template match="h:*">
  <xsl:param name="level" select="1"/>
  <xsl:variable name="level-classes" select="key('style-by-level',
$level, $styles-doc)//@style:name
  <xsl:variable name="level-elements" select="key('element-by-class',
$level-classes)"/>
  <li>
    <xsl:value-of select="."/>
    <ol>
      <xsl:apply-templates="$level-elements">
        <xsl:with-param name="level" select="$level + 1"/>
      </xsl:apply-templates>
    </ol>
  </li>
</xsl:template>

But this gives problems since levels are not necessarily consecutive.
The first level can be 2, for example.
I also tried iterating only through actually used levels like (1, 3,
5), but it's not a full solution either, because the level hierarchy
can differ in each branch.

Help appreciated.

Martynas
odt2epub.com

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.