[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: how to get position()

Subject: Re: how to get position()
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 5 Aug 2002 00:56:57 -0600 (MDT)
html get position
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.