-3

In my XSLT 2.0 file, I have to define a static variable say counter and will be using this variable under a for-each() loop. I need to increment this static variable value by 10.

Says for each look, this variable value should be in incremented by 10,20,30,40. Internally I will be assigning this variable to one of target schema element.

Can someone please hep or help me redirecting to relevant post.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
kumarb
  • 521
  • 1
  • 7
  • 23
  • 3
    There won't be a relevant post for this, as XSLT is a functional language, and variables are "immutable" in it, meaning they can't be changed once set. Instead of saying how you are trying to solve a particular problem, you say what your problem is, as it can probably be solved in a different way, that may need not variables at all. (Possibly by using the `position()` function for example). Thank you! – Tim C Feb 14 '16 at 09:29

1 Answers1

0

It is not possible to increment a variable within a xsl:for-each loop, because xsl:for-each is not a loop1.

You could, however, use the position() function to increase a static variable incrementally, e.g.:

$staticVariable + 10 * position()

--
[1] Except: http://www.saxonica.com/documentation/index.html#!extensions/instructions/assign

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51