Ticker

6/recent/ticker-posts

Bi Publisher – Using variables in rtf

 

Let’s see how we can use the variables to store temporary data or use for calculation.  This is achieved using “xdoxslt:” function. These are the BI Publisher extension of standard xslt functions.  

Use xdoxslt:set_variable () function to set /initialize the variable  and xdoxslt:get_variable() function to get the variable value.  $_XDOCTX is the System variables to set the XDO Context.

Syntax:

Decalring the Variable : <?xdoxslt:set_variable($_XDOCTX, 'variable name', value)?> 

Method to do the calculation :
<?xdoxslt:set_variable($_XDOCTX, 'x', xdoxslt:get_variable($_XDOCTX, 'x' + 1)?>
This sets the value of variable 'x' to its original value plus 1, much like using "x = x + 1". 

Display/retrieve the Variable :
<?xdoxslt:get_variable($_XDOCTX, 'variable name')?>
 
Setting Parameters:

You can pass runtime parameter values into the template.

These can then be referenced throughout the template to support many functions. For example, you can filter data in the template, use a value in a conditional formatting block, or pass property values (such as security settings) into the final document.

To use a parameter in a template:

  1. Declare the parameter in the template.

Use the following syntax to declare the parameter:

<?param@begin:parameter_name;parameter_value?>

where

parameter_name is the name of the parameter

parameter_value is the default value for the parameter (the parameter_value is optional)

param@begin: is a required string to push the parameter declaration to the top of the template at runtime so that it can be referred to globally in the template.

The syntax must be declared in the Help Text field of a form field. The form field can be placed anywhere in the template.

  1. Refer to the parameter in the template by prefixing the name with a "$" character. For example, if you declare the parameter name to be "InvThresh", then reference the value using "$InvThresh".
  2. If you are not using BI Publisher Enterprise, but only the core libraries:

At runtime, pass the parameter to the BI Publisher engine programmatically.

Prior to calling the FOProcessor API create a Properties class and assign a property to it for the parameter value as follows:

Properties prop = new Properties();

prop.put("xslt.InvThresh", "1000");

Example: Passing an invoice threshold parameter

This example illustrates how to declare a parameter in the template that filters the data based on the value of the parameter.

The following XML sample lists invoice data:

<INVOICES>

 <INVOICE>

  <INVOICE_NUM>981110</INVOICE_NUM>

  <AMOUNT>1100</AMOUNT>

 </INVOICE>

 <INVOICE>

  <INVOICE_NUM>981111</INVOICE_NUM>

  <AMOUNT>250</AMOUNT>

 </INVOICE>

 <INVOICE>

  <INVOICE_NUM>981112</INVOICE_NUM>

  <AMOUNT>8343</AMOUNT>

 </INVOICE>

. . .

</INVOICES>

The following illustration shows a template that accepts a parameter value to limit the invoices displayed in the final document based on the parameter value.



Scenarios:

/*initialize a variables*/

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

/*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’)?>

Below is one example which shows, if you need to use variables in rtf to do some calculations like adding two number etc, this is how you go about doing so.

The following e.g. shows how to add 1 to any value

Initialize a variable to 0 where A is the name of the variable :

<?xdoxslt:set_variable($_XDOCTX, ‘A’, 0)?>

add 1 to A :

<?xdoxslt:set_variable($_XDOCTX,’A’,xdoxslt:get_variable($_XDOCTX,’A’)+1)?>

Display the value A:

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

Adding two column values in rtf

Initialize variable A:

<?xdoxslt:set_variable($_XDOCTX, ‘A’, 0.00)?>

Initialize variable B :

<?xdoxslt:set_variable($_XDOCTX, ‘B’, 0.00)?>

Initialize variable A with column1 value:

<?xdoxslt:set_variable($_XDOCTX, ‘A’,xdoxslt:get_variable($_XDOCTX, ‘A’)+PEEVF_SCREEN_ENT)?>

where PEEVF_SCREEN_ENT is the value of column 1

Initialize variable B with column2 value:

<?xdoxslt:set_variable($_XDOCTX, ‘B’,xdoxslt:get_variable($_XDOCTX, ‘B’)+PEEVF_SCREEN_EN1)?>

PEEVF_SCREEN_EN1  is the value of Column 2

Assign value to 3rd variable with the value of A + B

<?xdoxslt:set_variable($_XDOCTX,’C’,xdoxslt:get_variable($_XDOCTX,’A’)+xdoxslt:get_variable($_XDOCTX,’B’))?>

Display the value of variable C:

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

 

 

 




Post a Comment

0 Comments