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

Re: Numbered Lists

Subject: Re: Numbered Lists
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Tue, 9 Oct 2001 17:23:23 -0400
numbered b
[Hewko, Doug]

> 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?

Yes - use variables!!! They make your job very easy.  Before getting into
that, though, your html is not doing what you think. You are creating <a>
sections with no content which is unlikely to work and shows nothing
visible, and your HREF parts are not getting traversed at all.

Here is a stylesheet that does what you said you want, except it doesn't do
indenting or hrefs.  I can see that you can handle them, anyway.  This
example numbers things as you wanted:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method='html' />

<xsl:variable name='chapters' select='/root/chapter'/>

<xsl:template match="/">
<body>
 <xsl:for-each select='$chapters'>
     <xsl:variable name='chapnum' select='position()'/>
     <h3>
        <xsl:value-of select='$chapnum'/>&#160;
        <xsl:value-of select='name'/><br/>
     </h3>
     <xsl:variable name='sections' select='section'/>

     <xsl:for-each select='$sections'>
        <h4>
        <xsl:value-of select='$chapnum'/>.<xsl:value-of
           select='position()'/>&#160;
        <xsl:value-of select='name'/>
         </h4>
     </xsl:for-each>
 </xsl:for-each>
</body>
</xsl:template>

</xsl:stylesheet>

=====================================
Here is the result:

<body>
<h3>1

  Name of first chapter<br></h3>
<h4>1.1

    Chapter 1 section 1</h4>
<h4>1.2

    Chapter 1 section 2</h4>
<h3>2

  Name of second chapter<br></h3>
</body>

=============================================

This displays just as you want.

As an aside, your stylesheet selected on section/name and chapter/name, when
the thing you were really processing was a section or a chapter.  It's
better to select on the main thing you are processing, not a child of it.

Cheers,

Tom P

>
> 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
>



 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.