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[(_at_)text:outline-level = $outline-level]">
<xsl:choose>
<xsl:when test="current-group()[1]/@text:outline-level =
$outline-level">
<xsl:text>
</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
--~------------------------------------------------------------------
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>
--~--