Skip Headers
Oracle® Fusion Middleware Report Designer's Guide for Oracle Business Intelligence Publisher
11g Release 1 (11.1.1)

Part Number E22254-02
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Feedback page
Contact Us

Go to previous page
Go to next page
PDF · Mobi · ePub

13 Designing RTF Subtemplates

This chapter describes how to use RTF subtemplates to create and reuse functionality across multiple BI Publisher reports.

This chapter includes the following sections:

13.1 Understanding RTF Subtemplates

An RTF subtemplate is an RTF file that consists of one or more <?template:?> definitions, each containing a block of formatting or commands.

This RTF file, when uploaded to BI Publisher as a Sub Template object in the Catalog, can be called from other RTF templates.

Figure 13-1 illustrates the composition of an RTF Sub Template.

Figure 13-1 Composition of an RTF Sub Template

Description of Figure 13-1 follows
Description of "Figure 13-1 Composition of an RTF Sub Template"

13.2 Process Overview for Creating and Implementing RTF Subtemplates

Using a subtemplate consists of the following steps (described in the following sections):

  1. Create the RTF file that contains the common components or processing instructions that you want to include in other templates.

  2. Create the calling or "main" layout and include the following two commands:

    • import - to import the subtemplate file to the main layout template.

    • call-template - to execute or render the subtemplate contents in the main layout.

  3. Test the template and subtemplate.


    You can use the BI Publisher Desktop Template Viewer to test the main layout plus subtemplate before loading them to the catalog. To do so, you must alter the import template syntax to point to the location of the subtemplate in the local environment. See Section 12.3, "Testing Subtemplates from the Desktop."

  4. Upload the main template to the report definition and create the Sub Template object in the catalog. See Section 12.4, "Creating the Sub Template Object in the Catalog."

13.3 Creating an RTF Subtemplate File

Enter the components or instructions in an RTF file. To define the instructions as a subtemplate, enclose the contents in the following tags:

      ..subtemplate contents...
<?end template?>


template_name is the name you choose for the subtemplate.

Note that in a single RTF file, you can have multiple

<?end template?>

entries, to mark different "subtemplates" or segments to include in other files.

For example, Figure 13-2 shows a sample RTF file that contains two subtemplates, one named commonHeader and one named commonFooter.

Figure 13-2 Sample RTF File

Description of Figure 13-2 follows
Description of "Figure 13-2 Sample RTF File"

13.4 Calling a Subtemplate from a Main Template

To implement the subtemplate in a main template, you must make two entries in the main template:

First, import the subtemplate file to the main template. The import syntax tells the BI Publisher engine where to find the Sub Template in the catalog.

Second, enter a call command to render the contents of the subtemplate at the position desired.

13.4.1 Importing the Subtemplate to the Main Template

Enter the import command anywhere in the main template prior to the call template command:

If you do not require a locale, enter the following:

<?import:xdoxsl:///path to subtemplate.xsb?>


path to subtemplate.xsb is the path to the subtemplate .xsb object in the catalog.

For example:



If the subtemplate resides in a personal folder under My Folders, the command to import the subtemplate is:

<?import:xdoxsl:///~username/path to subtemplate.xsb?>

where username is your user name.

For example, if user "myuser" uploads a subtemplate called "Template1" to a folder called "Subtemplates" under "My Folders", the correct import statement is:


13.4.2 Calling the Subtemplate to Render Its Contents

To call the subtemplate to render its contents:

  1. In the position in the main template where you want the subtemplate to render, enter the call-template command, as follows:



    template_name is the name you assigned to the contents in the template declaration statement within the subtemplate file (that is, the <?template:template_name?> statement).

Figure 13-3 illustrates the entries required in a main template.

Figure 13-3 Required Entries in Main Template

Description of Figure 13-3 follows
Description of "Figure 13-3 Required Entries in Main Template"

13.4.3 Importing a Localized Subtemplate

To designate the locale of the imported subtemplate, append the locale to the import statement as follows:

<?import:xdoxsl:///{path to subtemplate.xsb}?loc={locale_name}?>


path to subtemplate.xsb is the path to the subtemplate .xsb object in the catalog


locale_name is the language-territory combination which comprises the locale. The locale designation is optional.

For example:


Note that you can also use ${_XDOLOCALE} to import a localized subtemplate based on the runtime user locale. For example:


13.4.4 Example

In this example, your company address is a fixed string that is displayed in all your templates. Rather than reproduce the string in all the templates, you can place it in one subtemplate and reference it from all the others.

To place the string in a subtemplate and reference it:

  1. In an RTF file enter the following template declaration:

    My Company
    500 Main Street
    Any City, CA 98765
    <?end template?>
  2. Create a Sub Template in the catalog in the following location: Customer Reports/Templates.

  3. Upload this file to the Sub Template and save it as "Common Components" (BI Publisher assigns the object the .xsb extension).

  4. In the main template, enter the following import statement in a form field or directly in the template:

    <?import:xdoxsl:///Customer Reports/Templates/Common Components.xsb?>
  5. In the main template, in the location you want the address to appear, enter


At runtime the contents of the MyAddress subtemplate are fetched and rendered in the layout of the main template.

This functionality is not limited to just strings, you can insert any valid RTF template functionality in a subtemplate, and even pass parameters from one to the other. For examples, see the next section: Section 13.5, "When to Use RTF Subtemplates."

13.5 When to Use RTF Subtemplates

Following are several common use-cases for RTF subtemplates.

13.5.1 Reusing a Common Layout

Frequently multiple reports require the same header and footer content. By using an RTF subtemplate to contain this content, any global changes are simplified and require updating only the subtemplate instead of each individual layout.

13.5.2 Conditionally Displaying a Layout Based on a Value in the Data

Subtemplates can also be used to apply conditional layouts based on a value in the report data.

By using the RTF template "choose" command, you can instruct BI Publisher to apply a different <?template?> defined in the subtemplate file.


You cannot conditionalize the import statement for the subtemplate file. Instead, you import one subtemplate file and conditionalize the call statement. You define the multiple <?template?> options in the single subtemplate file. Example

Assume you have a report that is sent to customers in India and the United States. You must apply a different address layout depending on the country code (COUNTRY_CODE) supplied in the data. This example uses the RTF templates "if" statement functionality to call the subtemplate with the appropriate address format.

The subtemplate file might look like the following:

<?end template?>

<?end template?>

To call the subtemplate with the appropriate address format:

  1. Create a Sub Template in the catalog in the following location:

    Customers/Invoice Reports

    Upload the RTF file and save the Sub Template as "Addresses".

  2. In the main template enter the following to import the Sub Template:

    <?import:xdoxsl:///Customers/Invoice Reports/Addresses.xsb?>
  3. In the location where you want the address to display, enter the following:

         <?end if?>   
         <?end if?>    

When the report is run, the address format is properly applied, depending on the value of COUNTRY_CODE in the data.

13.5.3 Conditionally Displaying a Layout Based on a Parameter Value

This example illustrates how to display a different layout based on a user parameter value or a selection from a list of values. The parameter can be passed to the RTF template and used to call a different <?template?> within the subtemplate file based on the value.


You cannot conditionalize the import statement for the subtemplate file. Example

Assume in the report data model that you have defined a parameter named DeptName. You set up this parameter as type Menu and associated it to a list of values, enabling your user to make a selection from the list when he views the report in the Report Viewer (or when he schedules the report).

In the RTF main layout template, enter the following command to capture the value chosen by the user:


To display the layout based on this user selection, you can use an IF statement or a CHOOSE statement to evaluate the parameter value and call the associated subtemplate.

Use the CHOOSE statement when there are many conditional tests and a default action is expected for the rest of the values. For example, the Accounting, Sales, and Marketing departments each require a different layout. All other departments can use a default layout.

To display the layout:

  1. Create an RTF file and include the following template declarations:

       -  -  -  Specific Accounting Layout here  -  -  - 
    <?end template?>
       -  -  -  Specific Sales Layout here  -  - -
    <?end template?> 
       -  -  -  Specific Marketing Layout here - -
    <?end template?> 
       -  -  -  Default Layout here  -  - -
    <?end template?>
  2. Create a Sub Template in the catalog in the following location:

    Shared Folders/Executive/Department Expenses

    Upload the RTF file and save the Sub Template as "DeptSubtemps".

  3. In the main RTF template, include the following commands:

<?import:xdoxsl:///Executive/Department Expenses/DeptSubtemps.xsb?loc=en-US?>


   <?end when?>
   <?end when?>
   <?end when?>
   <?end otherwise?>
<?end choose:?>

When the user runs the report, the layout applied is determined based on the value of DeptName. For more information on CHOOSE statements in RTF templates, see Section 4.10.4, "Inserting Choose Statements." Handling Simple Calculations or Repeating Formulae

Simple calculations can also be handled using an RTF subtemplate. More complex formulae should be handled with an XSL subtemplate. Example

This example illustrates setting up a subtemplate to contain a formula to calculate interest.

The subtemplate performs the interest calculation on the data in this report and passes the result back to the main template. The subtemplate accommodates the possibility that multiple reports that call this functionality might have different tag names for the components of the formula.

Assume that you have the following XML data:


To set up a subtemplate to contain a formula for calculating interest:

  1. In an RTF file, create a template declaration called "calcInterest". In this subtemplate define a parameter for each of the elements (principal, interest rate, and years) in the formula. Note that you must set the default value for each parameter.

       <?number($principal) * number($intRate) * number($years)?>
    <?end template?>
  2. Create a Sub Template in the catalog in the following location:

    Shared Folders/Subtemplates

    Upload the RTF file and save the Sub Template as "calculations".

  3. In the main template enter the following to import the subtemplate:

  4. In the location where you want the results of the calculation to display, enter the following in a BI Publisher field:

    <?end call?>      

    Note the use of the @inlines command here. This is optional. The @inlines command forces the results to be rendered inline at the location in the template where the call to the subtemplate is made. Use this feature, for example, if you want to keep the results on the same line as a string of text that precedes the call.

13.6 Adding Translations to an RTF Subtemplate

RTF subtemplates offer the same support for translations as RTF template files.

You can upload multiple translated RTF files under a single Sub Template definition and assign the appropriate locale. These are displayed in the Templates region, as shown in Figure 13-4.

Figure 13-4 Templates Region

Description of Figure 13-4 follows
Description of "Figure 13-4 Templates Region"

Or you can generate an XLIFF (.xlf) file of the translatable strings, translate the strings, and upload the translated file. These are displayed in the Translations region, as shown in Figure 13-5.

Figure 13-5 Translations Region

Description of Figure 13-5 follows
Description of "Figure 13-5 Translations Region"

At runtime, the appropriate subtemplate localization is applied based on the user's account Preference setting for Report Locale for reports viewed online; or, for scheduled reports, based on the user's selection for Report Locale for the scheduled report.

The XLIFF files for subtemplates can be generated individually, then translated, and uploaded individually. Or, if you perform a catalog translation that includes the Sub Template folders, the strings from the subtemplate files are extracted and included in the larger catalog translation file. When the catalog translation file is uploaded to BI Publisher, the appropriate translations from the catalog file are displayed in the Translations region of the Sub Template definition.

For more information on translations, see Chapter 15, "Translation Support Overview and Concepts."