This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: xsl:number question



Perry Molendijk writes:
>The onscreen output (html) looks like this:
>One - 2
>Two - 4
>Three - 6
>Four - 8
>This could be a usefull feature but I want the numbers 1,2,3...

There are some rules-of-thumb about xsl:number which you can
apply here, if you have enough thumbs.

1. Use xsl:number to generate numbering for output, not for
   general counting. (Mnemonic: that's why it's in chapter 7
   of the XSLT spec.)

In the example you sent, you are only using xsl:number for
display, so you can drop all that stuff about putting the
number in a variable.

2. There are well-targeted counting options in xsl:number,
   so try to let it do the work for you.

In your example, you used "value=position()" and thus
over-rode its built-in ability to count only the form
nodes. As a corollary to the above,

2A. Start with just plain <xsl:number>, then tinker with
    count, level, from, position, and format, IN THAT
    ORDER, to get what you need. (All other attributes
    come later, to tweak the appearance.)

Yes, you could do "value=position() div 2" but that would
be highly dependent on the regularity of the structure
and the intervening whitespace. If "count=form" is what
you want, say so. Actually, that should be the default
for your example.

3. Ultimately, xsl:number is creating strings.
   (Mnemonic: it can generate "numbers" with more than
   one decimal point, or with other separators.)

If you need position data for other reasons not shown in
your example, use separate expressions with position()
or count(node-set) to perform numerical calculations.
I hope this gives you a fresh outlook on the task.
.................David Marston



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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]