This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: how to get position()
- From: Mike Brown <mike at skew dot org>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 5 Aug 2002 00:56:57 -0600 (MDT)
- Subject: Re: [xsl] how to get position()
- Reply-to: xsl-list at lists dot mulberrytech dot com
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