Increment Counter in For-Each Loop for RTF Template

noobie picture noobie · Feb 26, 2015 · Viewed 9.8k times · Source

I am trying to increment COUNTER variable by 1 inside a for-each loop of BIP report using below code.

However, COUNTER variable are not incremented not matter how many loop there is. Can someone please guide me how to do this.

Also I am aware of position() function but it does not suffice my needs.

<?xdoxsllt:set_variable($_XDOCTX, 'COUNTER', 1)?>

<?for-each@section:SECTION1?>
    <?xdoxslt:set_variable($_XDOCTX, 'COUNTER', xdoxslt:get_variable($_XDOCTX, 'COUNTER') + 1?>
<?end for-each?>

<?xdoxslt:get_variable($_XDOCTX, 'COUNTER')?>

Answer

PAVAN SAVLANI picture PAVAN SAVLANI · Nov 19, 2018

You were Missing two things: 1. 'xdoxslt' in the first line was written as 'xdoxsllt' 2. A closing braces after 1 in line no.3

<?xdoxslt:set_variable($_XDOCTX, 'COUNTER', 1)?>
<?for-each@section:SECTION1?>
    <?xdoxslt:set_variable($_XDOCTX, 'COUNTER', xdoxslt:get_variable($_XDOCTX, 'COUNTER') + 1)?>
<?end for-each?>
<?xdoxslt:get_variable($_XDOCTX, 'COUNTER')?>