This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]