Re: Dynamic numbering of lists in xslt
So, in my xslt, I use:
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 --> </xsl:template>
<!-- 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.
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.
Cheers, -- Abel Braaksma http://www.nuntia.nl
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format