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

Numbered Lists

Subject: Numbered Lists
From: "Hewko, Doug" <Doug.Hewko@xxxxxxxxxxxxxxx>
Date: Tue, 9 Oct 2001 16:04:07 -0400
xml numbered lists
How can I generate a numbered list for a table of contents in XSL? I can
generate and indent the table of contents, but I can't get the numbering to
work. I thought of using the count() function. That works nicely for the
chapters in the contents, but fails for the chapter names in the document.
(They should match.) I thought of using a variable, but that seems quite
messy. Any suggestions?

My XML document is like this:
	<root>
		<chapter><name>Name of first chapter</name>
			<section><name>Chapter 1 section 1</name></section>
			<section><name>Chapter 1 section 2</name></section>
		<chapter><name>Name of second chapter</name>
	</root>

I want my document to be like this:
	TABLE OF CONTENTS
	1. Name of first chapter
	   1.1 Chapter 1 section 1
	   1.2 Chapter 1 section 2
	2. Name of second chapter

Here's my XSL:
<xsl:template match="/">
	<ul>
	<xsl:for-each select="chapter/name">
		<li><a>
		<xsl:attribute name="HREF">#<xsl:value-of
select="generate-id()"/></xsl:attribute>
		<xsl:value-of select="position()"/>.&#160;<xsl:value-of
select="."/>
		<ul>
			<xsl:for-each select="../section/name">
			<li><a>
			<xsl:attribute name="HREF">#<xsl:value-of
select="generate-id()"/></xsl:attribute>
			<xsl:value-of select="."/>
			</a></li>
		</xsl:for-each>
		</ul>		
		</a></li>
	</xsl:for-each>
	</ul>
	</td></tr></table></center>
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="section/name">
	<h3><a><xsl:attribute name="NAME"><xsl:value-of
select="generate-id()"/></xsl:attribute><xsl:value-of
select="position()"/><xsl:value-of select="."/></a></h3><br/>
</xsl:template>

<xsl:template match="chapter/name">
	<h2><a><xsl:attribute name="NAME"><xsl:value-of
select="generate-id()"/></xsl:attribute><xsl:value-of
select="position()"/><xsl:value-of select="."/></a></h2><br/>
</xsl:template>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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