S
Stefan Kleineikenscheidt
Hi all,
i'm trying to convert an HTML page to a hierachical structure, but I am
stuck. Consider a page like that:
<h1>First Heading1</h1>
<p>some text</p>
<p>more text</p>
<h2>First Heading2</h2>
<p>more text</p>
<h2>Second Heading2</h2>
...
<h1>Second Heading1</h1>
...
<h2>Third Heading2</h2>
...
Now I would like to convert this into a hierarchical structure like
this (think of Docbook):
<article>
|
+ <sect1>
| |
| + <sect2>
| + <sect2>
|
+ <sect1>
|
+ <sect2>
This is my 'h1' template, where i try to process all elements between
two 'h1' elements:
<xsl:template match="//h:h1">
<section>
<title><xsl:value-of select="text()" /></title>
<xsl:variable name="nexth1" select="position(parent::*/*[(name()
= 'h1')])" />
<xsl:apply-templates select="following-sibling::*[position()
<= $nexth1]" />
</section>
</xsl:template>
$nexth1 should be the position of the next 'h1' element. However,
position() does not take any arguments, and i don't have a clue how to
get the position. (I need to change the context node, but i don't know
how...)
Can you give me any directions on this?
Thanks in advance,
-Stefan
i'm trying to convert an HTML page to a hierachical structure, but I am
stuck. Consider a page like that:
<h1>First Heading1</h1>
<p>some text</p>
<p>more text</p>
<h2>First Heading2</h2>
<p>more text</p>
<h2>Second Heading2</h2>
...
<h1>Second Heading1</h1>
...
<h2>Third Heading2</h2>
...
Now I would like to convert this into a hierarchical structure like
this (think of Docbook):
<article>
|
+ <sect1>
| |
| + <sect2>
| + <sect2>
|
+ <sect1>
|
+ <sect2>
This is my 'h1' template, where i try to process all elements between
two 'h1' elements:
<xsl:template match="//h:h1">
<section>
<title><xsl:value-of select="text()" /></title>
<xsl:variable name="nexth1" select="position(parent::*/*[(name()
= 'h1')])" />
<xsl:apply-templates select="following-sibling::*[position()
<= $nexth1]" />
</section>
</xsl:template>
$nexth1 should be the position of the next 'h1' element. However,
position() does not take any arguments, and i don't have a clue how to
get the position. (I need to change the context node, but i don't know
how...)
Can you give me any directions on this?
Thanks in advance,
-Stefan