[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Numbering
Subject: Re: Numbering
From: kobily <kobily@xxxxxxxxxxxx>
Date: Wed, 10 Oct 2001 20:19:33 +0200
|
Hi Jenny
Here is the real case:
Part of the template match="root"
<select size="6" name="available">
<xsl:apply-templates select="*|@*|text()"/>
</select>
The template I´m calling:
<xsl:template match="@*|text()">
<xsl:if test="normalize-space(.)!=''">
<option value="{position()}">
<xsl:for-each select="ancestor::*">/<xsl:value-of
select="local-name(.)"/></xsl:for-each>
</option>
</xsl:variable>
</xsl:if>
</xsl:template>
In this case, I get an html with:
<select name="second"><option value="1">/root/url</option><option
value="1">/root/tags/a</option><option
value="1">/root/tags/b</option><option
value="1">/root/tags/c</option><option
value="1">/root/tags/e</option><option
value="1">/root/tags/f</option><option
value="1">/root/tags/g</option><option
value="1">/root/tags/i</option><option
value="1">/root/tags/j</option></select>
So, I could not use position.
I hope you could help me.
Regards
jeni@xxxxxxxxxxxxxxxx wrote:
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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
- Numbering
- kobily - Wed, 10 Oct 2001 13:24:27 -0400 (EDT)
- Jeni Tennison - Wed, 10 Oct 2001 13:50:42 -0400 (EDT)
- kobily - Wed, 10 Oct 2001 14:30:24 -0400 (EDT) <=
- Michael Kay - Thu, 11 Oct 2001 04:26:41 -0400 (EDT)
|
|
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
RSS 2.0 |
|
Atom 0.3 |
|
|