Monday, November 23, 2009

Common Header and Footer Style with Sub Template

When you develop a report you usually want to have a header and footer section. And when you develop more reports you probably copy and paste the header and footer section from the first report so that all the reports will have a same look and feel with a company logo, report title, reporting date, copy right, etc.

Now you have developed a lot of reports with the same header and footer and you need to change the report title font size or need to change the company logo in the header section, what would you do? Imagine if you have 100 reports already developed! Obviously you don’t want to visit every single report and make such changes in each of the RTF templates.

In order to avoid from visiting each of those hundreds of the reports you wish having just one common header and footer template, in which you can design the header and footer and you can import from all the reports you have. When you need to make such changes for the header and footer only you need to do is to visit only this common header and footer template and make the change. How easy!

This is a very common requirement for any reports development with BI Publisher and BI Publisher addresses this type of requirement with its Sub-Template feature. But somehow it can often be slipped out from the reports design until you hit this maintenance concern mentioned above. I guess that’s because our main focus is how to bring the data into the report and design the layout and formatting for the data when we start the development and we just want to get our report done without taking an account of the long term maintenance perspective.

Also this is not really well documented as a practical and best practice way. There are many information about this common template (called Sub Template in BI Publisher) out there but it’s not really clear as a complete picture of how to implement it and deploy to a real environment.

So here comes the post I’m writing today. I’m writing this using an example of the header and footer, but as you can imagine it doesn’t have to be only for the header and footer. Anything you want to have in a central place and apply to all the reports you can apply this information.

Sub-Template as Common Template

With BI Publisher you can use a Sub-Template feature to create the common template where you can design common objects such as the header and footer. The Sub-Template can be a RTF template or XSL style sheet, which can contain common formatting and layout information, and can be imported from any reports. So for example if you want to have a same header layout then you can design the header in the Sub-Template file and import the header, which you just designed in the Sub-Template, from all of your RTF template files. When you get a new requirement or modification request for the header then you can only modify this one header in the Sub-Template file and no extra work needed.

Common Template Development

Here is a list of the steps how you can implement the common Header and Footer Sub-Template.

Steps:

  1. Create a Sub-Template for the Header and Footer
  2. Locate the Sub-Template at a Web Server or file system that BI Publisher server can access to
  3. Call the Sub-Template from the main templates
  4. Call the header or footer section

 

Create a Sub-Template for the Header and Footer

You can create a new RTF template and use a ‘template’ syntax to design the header or footer layout and formatting.

Template Syntax:

<?template:%template_name%?>

There is a starting syntax (<?template….?> and ending sytax (<?end template?>), so you need to design the header or footer layout first then surround it with the starting template and the ending template syntax.

Example:

<?template:header?>

Header contents should be here…

<?end template?>

 

Locate the sub-template at a common directory (folder), which BI Publisher server can access to

Once you created the sub-template now you can reference it from the main RTF template files. It can be referenced by either File or HTTP option. The File option is to locate the sub-template file on the file system, which means the sub-template needs to be on the same machine where the main template files are. The HTTP option is for the sub-template to be accessed through HTTP so the sub-template needs to be on a web server and it should be accessible from other machines with HTTP.

Call Sub-Template

Import the sub-template from the main templates

First, you need to import the sub-template in the main RTF template. You can import either with File or HTTP option. This import statement needs to be set at the very beginning of the file.

Here is the example:

Example with File reference:

<?import:file:/// C:\BIP\SubTemplate\common_template.rtf?>

Example with HTTP reference:

<?import:http://knishida-lap.us.oracle.com:9704/bip/common_template.rtf?>

Call the header or footer section

Once you imported, now you can use ‘call-template’ syntax to call and embed the header or footer layout and formatting at the header or footer section in the main template.

Example:

<?call-template:header?>

And, that’s it! Now you have a common header and footer template and can apply it to any report you have. Very simple.

I will discuss tomorrow about some best practice on how to deploy and tips. So stay tuned!

10 comments:

  1. very cool. it really helps

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I'm having a little trouble following your tutorial about sub templates,I have a for-each inside the sub template, and it has a conditional page break, my problem is that the first page renders correctly, showing only rows 1-4 but from the second page it shows all rows is not respecting my conditional page break for the next 4 rows.

    The code to control page breaks is the following:
    "
    < ?if:position() mod 4=0? >
    < xsl:attribute name="break-before">page< /xsl:attribute >
    < ?end if? >
    "
    (I put some blank spaces so it doesn't be taken as code on this blog entry)

    this code is before the field containing the

    hope you can help me with this.

    Regards

    ReplyDelete
  4. Hi,

    Is there any way to upload subtemplates into server using Webservices

    ReplyDelete
  5. If you're on 10G, you can't really upload the sub-template then reference. So I'd recommend you place the sub-template files on a http server like the example above. However, with 11G you can upload your sub-template and reference to it from another report much easier all in the BI Publisher UI, and you can upload it with the WS. I'm planning to write this sub-template/style template with 11g pretty soon, so follow us on twitter @bipublisher and stay tuned!

    ReplyDelete
  6. i tried to go through many blogs..this one clearly explains about the sub template design and steps.

    Thanks a lot!

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Hi,

    I followed your example of sub template concept.

    But it seems i am facing an issue in running the request.

    I am working on oracle EBS , i am developing a report on BI publisher.

    My requirement is when the concurrent request is submitted, it should generate 2 copies of the output.

    One is for Customer Copy and other is Office copy for filing purpose.

    I approached.Sub template concept.
    My Bi Publisher desktop version is 10.1.3.2.1.

    Please let me know how i can address this requirement.

    Thanks and regards,


    ReplyDelete
  9. Hi Kan,

    I am using BI publisher 10.1.3.

    Now I have created 2 subtemplates(1 is for Sewdish and 1 is for English lang.)-

    It is working fine when calling from BI Publisher Desktop (MS Word) using this syntax













    If bill to customer is in Sweden it displays template2 otherwise template1

    But it does not work when I moved this report to the server thru xml publisher responsibility-
    I am using this code:















    Am I doing something wrong while import/call the subtemplate. Could you please check the syntax? Here XXMI is our customize application wheer the subtemplate is defined.

    Thanks,

    Joohi

    ReplyDelete