xsl-list
[Top] [All Lists]

Re: [xsl] Recursively traversing an outline with level gaps

2010-03-24 13:56:32
Where are the sample Xhtml and xml documents?

On Wed, Mar 24, 2010 at 11:51 AM, Martynas Jusevicius
<martynas(_dot_)jusevicius(_at_)gmail(_dot_)com> wrote:
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
I enjoy the massacre of ads. This sentence will slaughter ads without
a messy bloodbath.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--