This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Numbering
- To: kobily <kobily at netscape dot net>
- Subject: Re: [xsl] Numbering
- From: Jeni Tennison <jeni at jenitennison dot com>
- Date: Wed, 10 Oct 2001 18:40:08 +0100
- CC: XSL-List at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <3BC481BB.8040408@netscape.net>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Kobily,
> This should be only for the elements that have content (tgis have
> been solved), my problem is to give the number of each elem. I canīt
> increase a variable. Iīm using:
>
> <xsl:variable name="values">0</xsl:variable>
> <xsl:for-each select="elem">
> <option><xsl:attribute name="value"><xsl:value-of select="$values +
> 1"/></xsl:attribute><xsl:value-of select="elem"/></option>
> </xsl:for-each>
>
> But the variable "values" is always 1.
Variables are strange in XSLT, in that they don't vary. But XSLT gives
you other ways of doing what you want to do. In your case, you can use
the position() function to get a counter telling you which elem you're
currently on. So you can do:
<xsl:for-each select="elem">
<option>
<xsl:attribute name="value">
<xsl:value-of select="position()" />
</xsl:attribute>
<xsl:value-of select="." />
</option>
</xsl:for-each>
Or, more simply using an attribute value template:
<xsl:for-each select="elem">
<option value="{position()}">
<xsl:value-of select="." />
</option>
</xsl:for-each>
[I've assumed that the content of the option element should be the
value of the current elem, not the value of the elem element child of
the current elem element.]
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list