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

Re: Dynamic numbering of lists in xslt

Subject: Re: Dynamic numbering of lists in xslt
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 09 Jan 2007 17:13:26 +0100
Re:  Dynamic numbering of lists in xslt
xslt.new wrote:
So, in my xslt, I use:

<xsl:when test="section='second section'>
  <!-- Do not display thi section -->

my output has:

1. first section
3. third section
4. fourth section

This is part of a huge issue that I am facing and so pasting the whole
XSLT here might be too cumbersome.

It is likely that your current approach is not the right xslt way of doing things, since you talk of a lot of xsl:choose and of a 'huge' structure. This tends to happen when people, coming from imperative languages like C++, Java, VB, Perl, PHP have to think in declarative and functional terms.

The easiest thing to do is: replace you xsl:choose with a (simpler) xsl:template approach, like this:

<xsl:template match="section[. != 'second section']">
  <!-- do display these sections -->

  <xsl:number />  <!-- will only count the matches consecutively -->

<!-- probably you can leave this one out -->
<xsl:template match="scrion[.='second section']" />

Considering you are talking of a "huge" structure, it may so happen that changing the choose-approach to a somewhat xslt-esquer approach lessens your codebase by some percentage. Better yet, it will make it more readable and it will leave calculating the best way to nirvana to the processor, instead of you, the programmer, leaving you with more time to do things like formatting numbers.

Can you give me any idea on how to number sequentially even if the preceding or folowing siblings are filtered?

Sounds to me like you want something like this:

if (condition) add 1 to counter, print counter

However, this is not the way to go and assignment is not possible in XSLT.

-- Abel Braaksma

Current Thread


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.
First Name
Last Name
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.