Hi All,
I'm new to XSLT, so here's my first problem. I'm attempting at automatically created a Table of Contents. I'm having problems creating the correct number to the left of the heading. For example, this is the output I want (given the example XML data provided):
1 This is a heading
2 This is another heading
2.1 This is a subheading
2.1.1 This is a sub-subheading
2.1.2 This is a sub-subheading2
3 This is yet another heading
I have XML data which would be in the format of (the level attribute defines the level of indentation):
Code:
<structure level="1">
<header>This is a heading</header>
...
</structure>
<structure level="1">
<header>This is another heading</header>
...
</structure>
<structure level="2">
<header>This is a subheading</header>
...
</structure>
<structure level="3">
<header>This is a sub-subheading</header>
...
</structure>
<structure level="3">
<header>This is a sub-subheading2</header>
...
</structure>
<structure level="1">
<header>This is yet another heading</header>
...
</structure>
So far I have messed around with both using the count function and using xsl:number. I'm nowhere close, so figured I would ask for pointers. A snippit of my current xslt looks like this:
Code:
<xsl:for-each select="structure">
<xsl:value-of select="1 + count(preceding::structure)"/>
<xsl:value-of select="./header"/>
</xsl:for-each>
However, the output looks like this:
1 This is a heading
2 This is another heading
3 This is a subheading
4 This is a sub-subheading
5 This is a sub-subheading2
6 This is yet another heading
Thanks in advance,
Jesse