Subject: Re: how to get position()
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 5 Aug 2002 00:56:57 -0600 (MDT)
|
Vinoth Palaniappan wrote:
> If i calculate the expression "position() -1" as
> <xsl:for-each select="child::*">
> <xsl:variable name="test_var" select="position() -
> 1"></xsl:variable>
> <xsl:apply-templates> select="."></xsl:apply-templates>
> </xsl:for-each>
> I get the series i want(0, 1, 2..) but i'm unable to use the
> variable as
> <xsl:template match="nv_pair">
> <xsl:number level="single" count="nv_pair" from="nv_pair"/>
> <xsl:copy-of select="$test_var"/>
> </xsl:template>
> because i get an error that the variable is "out-of-context". How can i
> bring that variable within the scope(context).
You can pass it as a parameter to the template that you are calling,
but there's no need to even do that. Instead of the for-each, do this:
<xsl:apply-templates select="*"/>
And then you can use position() within the templates that match.
For example, instead of the xsl:copy-of, use
<xsl:value-of select="position() -1"/>
- Mike
____________________________________________________________________________
mike j. brown | xml/xslt: http://skew.org/xml/
denver/boulder, colorado, usa | resume: http://skew.org/~mike/resume/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|