Wednesday 12 March 2014

Storing Values in Variables in your BI Publisher Template

Mike came up against an interesting issue the other day . he needed to access a value in the XML output from JDE on a different page . the trouble was the value was blank on the second page.  after a bit of digging I came across this  code which lets you store values in the XSL on your RTF template as variables

/*initialize a variable*/
<?xdoxslt:set_variable($_XDOCTX, ‘counter’, 0)?> or  
<?xdoxslt:set_variable($_XDOCTX,‘test‘,“wibble")?> 

/*get a variable*/
<?xdoxslt:get_variable($_XDOCTX, ‘test’)?>   

/*update the variable’s value by adding the current value to MY_CNT, which is XML element */
<?xdoxslt:set_variable($_XDOCTX, ‘counter’, xdoxslt:get_variable($_XDOCTX, ‘counter’) + MY_CNT)?>

/* accessing the variables */
<?xdoxslt:get_variable($_XDOCTX, ‘counter’)?>

/*Working in a loop*/
<?xdoxslt:set_variable($_XDOCTX, ‘counter’, 0)?>
<?for-each:G1?>

/*increment the counter*/
<?xdoxslt:set_variable($_XDOCTX, ‘counter’, xdoxslt:get_variable($_XDOCTX, ‘counter’) + 1)?>
<?end for-each?>

<?xdoxslt:get_variable($_XDOCTX, ‘counter’)?>

No comments:

Post a Comment