Wednesday, December 12, 2007

What Are Subtemplates?

Using Subtemplates

I found a fantastic way to make our lives as BIP developers a lot easier! It's called the subtemplate and it can be used over and over again. For example, if your company has a logo that they like to display on every report header, you can create a subtemplate that holds the image. Then, when you create the report template you call the subtemplate and your header logo is loaded into your report template. The same goes for report footers. If your company likes to display their name and address in the footer, you create another subtemplate with that information and call is in the footer of your report template. Everyone likes to find shortcuts, right? Well this shortcut could save you time and also make your reports more consistent because when you re-create the header for every report there is more room for error.

Another great thing about using subtemplates is that if you have to make a change to the company logo or address, you only have to make the change in one place and it shows on every report! Now, if you've already created templates without using subtemplates, I'm not trying to be a trouble maker and say to go back in and change them all.... but you should really convert over to this method for your next report. It will pay off in the long run!

So how do you use these things? You can create subtemplates by using XSL or XSLT (a transformation languages used with XML data for formatting) or you can create an .rtf document like we did in our last 2 examples. I found using an .rtf file is pretty straight forward in MS Word and it's also great for inserting a logo. You can still use XSL to format the data like we did in example1a for setting a default value, so don't worry about that.

Here is a short subtemplate example for ya....

First off, I modified the .xml file from example1a to add a date tag which will be used in our report header. You can download the new .xml file from http://www.mediafire.com/?0ce5ajbljmd
Next is our new subtemplate file that includes our company header and date that is an element name from our report output.






You can also download this from http://www.mediafire.com/?0ezjdthomyn . In this .rtf file we have our header and footer data as indicated by <?template:Header?> and <?template:Footer?>. Within those tags I created tables that are the same width as the report where I would like to add the header/footer. There is also a parameter tag <?param@begin:P_DATE?> . This tag creates a parameter that is used in the Header to display the date from the report data.

Lastly, we have our example2.rtf file where we call the subtemplate http://www.mediafire.com/?533dqzmjtjt




In MS Word, this is what is in the header. You are calling the 'header template' from the subtemplate and passing the value P_DATE from the .xml file to the subtemplate.




To link the report template with the subtemplate you have to import the subtemplate file in the report template body with the below syntax :
<?import:file:/// [path] subtemplate_file.rtf?>


You call the footer subtemplate the same way that you called the header subtemplate. As long as your header and footer are in the same .rtf file, you would only have to import the file one time in your report template body. Seeing that we aren't displaying and report data in the footer there are no parameters like in the header, but you could certainly add that if you so desire

So there you have it, our first look at using subtemplates.. enjoy!
Feel free to leave me comments and let me know if you found this helpful - BIPgirl

19 comments:

Tim Dexter said...

Heya BIPGirl
Excellent stuff as usual.
You are now at the top of the list of BIP Rollers at BIP grand central. You win a curly wurly and a Pork Pie from England. I bet you're pleased :0)

BIPgirl said...

Awesome.. a curly wurly! Thanks so much.

Gaby said...

Hey Bipgirl! Keep the good work... great blog so far!
GP

Manju Nambiar said...

Hey BIPGirl,
I was searching for how to add a Report header and came across your blog. Couple of questions - but before that let me explain the scenario to you:
I have a query bringing in the data. I have a template in place. Now I want add a report header(prints on the first page of the report) to the template. I tried what you suggested (created a sub template with the static image and static text - saved it as rtf - called it in my report template) - but when the updated the layout, on next view the BIP errored out.
can you please help me out?
Thanks,
Manju

BIPgirl said...

Hi Manju : Are you sure that the "import:file" statement to your subtemplate is correct and in the body of the template, not the header section? Without seeing the template I can't be 100% sure as to what is happening. What error are you getting? - BIPgirl

Manju Nambiar said...

Hey BIPGirl,
Thanks for the prompt reply.
To answer your question,yes, the import:file statement is correct - I just copied from your example and changed the path to point to my local template.
The thing is - I am adding this template to an already working and published template for a report. So when I add the import:file and call statements to the published template and update it, Word gives me no error.
But when I try to view the report on the BI server, it errors out without giving me any details.
My questions to you are:
1.How is the published template able to recognize the sub-template when the path is hard coded to my local machine?
2.If the path is not to be pointing to my local machine, then where should I place my sub-template?

If you can let me know how, I can send you my published template(inside which I am calling the sub-template), the sub-template and a picture of how the end report should look like.
Thanks,
Manju

BIPgirl said...

Hi Manju,
I have documentation from the Oracle developers guide that should help you. In my blog I haven't posted about using BIP in the Apps yet, so I was only showing how to use the subtemplate in Template Builder. That is why I am saying to put the local path to the subtemplate into the primary template.

Using a subtemplate consists of four steps:
1. Create the RTF subtemplate file

2. Register the subtemplate in the Template Manager. To define it as a
subtemplate, select Subtemplate = YES.

3. Enter the import syntax in the calling or "primary" template to import the subtemplate. The import syntax tells the XML Publisher engine where to find the subtemplate RTF in the Template Manager. This syntax may be entered anywhere in the template prior to the call-template syntax:
import:xdo://APPCODE.TEMPLATE_CODE.lang.TERR

- APPCODE is the Application code you assigned to the subtemplate in the Template Manager. (EX. AR)
-TEMPLATE_CODE is the template Code you assigned to the subtemplate
-lang is the two-letter ISO 639 language code9(EX. en)
-TERR is the two-letter ISO 3166 country code (EX. US)

4. Enter the call-template syntax in the primary template in the position that you want the subtemplate contents to render.

I hope this helps you out!

Manju Nambiar said...

Hey BIPGirl,
Actually I am using standalone BI Publisher (OBIEE 10.1.3.2). I dont see the template manager there. Is there any way to find out what is equivalent of the import command in BIP?
Happy Holidays and a Merry XMas and Happy New Year
Thanks,
Manju

BIPgirl said...

Hi again Manju,
I am not sure about the difference between the standalone and EBS versions. I would suggest to post your question on the Oracle BI Publisher forum at: http://forums.oracle.com/forums/forum.jspa?forumID=245

Happy Holidays to you as well!

Kim said...
This post has been removed by the author.
Kim said...

Hi BIPGirl,

First off, thanks for a great guide. It was very helpful. I have one question though, is it possible to use relative paths instead of absolute paths when writing your import statement in a template?

Thanks in advance

Kim

BIPgirl said...

Hi Kim,
I haven't tried this out using relative paths yet. Have you posted any questions about this to the BIP forum yet?

- BIPgirl

Kim said...

Hi again,

Yes, I have posted a question in the forum, but it hasn't been answered despite many views. I've searched a great deal on the subject, but haven't found an answer, so I guess relative paths aren't supported. So I hardcoded a workaround in java, which changes paths in the xsl runtime. If you find a better solution, please be kind to let me know.

Ketan Kothari said...

I think your syntax of passing parameters is not correct for this example. In the subtemplate you are referencing <?P_DATE?> which is the xml tag in the input file and is resolved automatically. You can test it by removing the with-param from the example2.rtf param from ex2_subtemplate. It will still bring the correct value.
In order to really make it work, you need to define a local param value in template as follows. XMLP syntax in my version generates incorrectly with no ending tag. Therefore you need to use xsl syntax in a word field.
<xsl:param name="P_DATE" />
Change <?P_DATE?> to <?$P_DATE?>
and in example.rtf do this.change <?with-param:P_DATE;$P_DATE?>
to
 <?with-param:P_DATE;P_DATE?>
Now you have correctly parameterized the sub template. If your input file does not contain P_DATE tag, then also it will work. You need to change the name in the calling template to appropriate tag.
If you have the same xml tag in all your reports, you really do not need parameter. In your sub template you can reference that tag directly and makes your sub template specific for that input xml file.

Anonymous said...

Hi BIGirl,

Can you use the import:file syntax to import a file that is specific in one of the value of the report's xml item tag? If so, how can this be accomplish.

Anonymous said...

in import for subtemplate, i dont want to hardcode the path. I want to specify relative path. example:
1. my subtemplates are in XMLP/Reports/subtemplates/header1.rtf
2. report rtf's in XMLP/Report/Report1/test.rtf

how to use relative path in the test.rtf to refer header1.rtf

This is in BI pulblisher 10.1.3.4

Anonymous said...

Hi BIGirl,

The Blog posted on the runtime parameters is excellent. I have an issue here in using the param@begin concept for printing the paramter values. This is failing when the runtime parameter value consists of an apostrophe character in the value string (Ex: Teacher's, Girl's etc...). Could you please suggest how to overcome this apostrophe characters in printing the value.

Your help is highly appreciated. Thanks in Advance.

Anonymous said...

Hi,

In the EBS environment we need to create report header sub template. We create template and sub template the same like you suggested and it work fine. But when we create a dynamics logo that depended on business logics function, the logo did not appear. For that purpose we create a sub template connected to data definition with data template that brings the proper logo file name.

Can you please resolve this?
Thanks
Ad

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!