Search code examples
foreachbi-publisher

Print multiple instances of same variable in BI Publisher


I was actually trying to print multiple values of the same attribute Title with comma after each but couldn't remove comma after the last value which resulted in me writing complex loops.

Here I have initiated a count variable storeCount which increments and until it reaches the number of rows returned, I print Title and a comma that follows. Here's my code. I am getting syntax error. I would appreciate help fixing the code.

<?for-each@inlines:G_1?>
    <?xdoxslt:set_variable($_XDOCTX, 'storeCounter', xdoxslt:get_variable($_XDOCTX, 'storeCounter') + 1)?>
    Title
    <?if@inlines:<?count(G_1)?> != <?xdoxslt:get_variable($_XDOCTX, 'storeCounter')?>?>
        ,
    <?end-if?>
<?end for-each?>

Solution

  • This should work:

    <?for-each@inlines:G_1?>
        <?xdoxslt:set_variable($_XDOCTX, 'storeCounter', xdoxslt:get_variable($_XDOCTX, 'storeCounter') + 1)?>
        Title
        <?if@inlines:count(G_1) != xdoxslt:get_variable($_XDOCTX, 'storeCounter')?>
            ,
        <?end-if?>
    <?end for-each?>