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

Re: Recursively traversing an outline with level gaps

Subject: Re: Recursively traversing an outline with level gaps
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Wed, 24 Mar 2010 22:26:06 +0100
Re:  Recursively traversing an outline with level gaps
Dear Martynas,

This not the complete solution that you asked for, with lookups in styles.xml and with HTML generation, but at least it deals with outline gaps. I put it in a function that takes all your nodes and groups them by the lowest outline level number present (which corresponds to the highest hierarchy level...), and then recursively groups the groups by the next level that is available. You can also find it on http://github.com/gimsieke/oo2teilite-xslt2/blob/master/oo2teilite.xsl

Gerrit


<xsl:function name="letex:hierarchize-by-outline" as="node()*">
<xsl:param name="nodes" as="node()*" />
<xsl:param name="outline-level" as="xsd:double*" />
<xsl:choose>
<xsl:when test="empty($outline-level)">
<xsl:sequence select="$nodes" />
</xsl:when>
<xsl:otherwise>
<xsl:for-each-group select="$nodes" group-starting-with="text:h[@text:outline-level = $outline-level]">
<xsl:choose>
<xsl:when test="current-group()[1]/@text:outline-level = $outline-level">
<xsl:text>&#xa;</xsl:text>
<div type="Heading_{$outline-level}">
<head>
<xsl:copy-of select="current-group()[1]/node()" />
</head>
<xsl:variable name="new-nodes" select="current-group()[position() gt 1]" as="node()*" />
<xsl:sequence select="letex:hierarchize-by-outline($new-nodes, min($new-nodes/@text:outline-level))" />
</div>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="letex:hierarchize-by-outline(current-group(), min(current-group()/@text:outline-level))" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:otherwise>
</xsl:choose>
</xsl:function>


On 24.03.2010 21:31, Martynas Jusevicius wrote:
Sorry, you're right. I can make a simplified test case:

ODT (styles.xml):
<style:style style:name="Heading_1" text:outline-level="1"/>
<style:style style:name="Heading_2" text:outline-level="2"/>
<style:style style:name="Heading_3" text:outline-level="3"/>
<style:style style:name="Heading_4" text:outline-level="4"/>

XHTML:
<p class="Heading_1">1</p>
...
<p class="Heading_3">1.1.1</p>
...
<p class="Heading_1">2</p>
...
<p class="Heading_2">2.1</p>
...
<p class="Heading_3">2.1.1</p>
...
<p class="Heading_2">2.2</p>

Desired outline (also what OpenOffice.org produces):
1
   1.1.1
2
   2.1
     2.1.1
   2.2

But if you process it recursively level after level as I described, you get:
1
2
   2.1
     2.1.1
   2.2

Notice 1.1.1 is missing, because 1.1 is missing as well -- in other
words, there is a gap between levels 1 and 3.

Does that make it clearer? How would you process such outline that all
the levels are included, no matter there are gaps between them?

Martynas

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-2011 All Rights Reserved.