An Oracle blog about BI Publisher

  • RTF
    July 2, 2008

Conditional Templates

One cool but confusing feature of the underlying standard to our RTF templates that is XSL-FO, is that you can create sub-templates and import them into your main template. This allows you to 'objectize' (yes another new word for the blog) your templates, do you have some common feature of all your templates? Rather than replicate that into every template, put it in one place and import it into the main templates. I have talked about that in prior articles. What's even cooler is that within your sub-template you can have multiple pieces of re-usable 'code'. Think of having a sub template with a header and footer section that can be pulled in. Now the slightly confusing bit - each of these pieces are themselves called 'templates'.
You can find yourselves having fantastic conversations about your main template calling the 'header' template from the sub-template, you don't? Well I do, maybe they are with myself but I have them!
Those of you that have gotten into the sub templating world will know the command to import a template:
<?import:[template URI]?>

then you can call a specific template within the main template:

What you may not know is that you can call the templates conditionally. Before we get to that thou, a note. You can not conditionally load the sub-template file i.e.
<?import:[template URI]?>
<end if?>

will not work. The import calls can not be executed at run time they are like pre-processor commands, like 'h' files in C.
With that said you can then conditionally call a template within that imported sub-template. There has been a question on the forum from Todd and I have had a similar conversation with Pat and the gang at Emulex recently.
Emulex have a good use case for conditional template calling. They have developed an RTF Purchase Order template that generates terms and conditions on the back of each page. They are now moving out of just using the PO for their domestic market and need it to work in an international arena. Translations aside, they just need a different set of terms and conditions for the international market version of the PO. They are already importing a T&Cs template - all they need to do is create a domestic and international T&C template within the sub-template. Their XML has a tag in it identifying what type of PO is being generated, so they can have something like:

<?when: .//TYPE=1?>
<?end when?>
<?when: .//TYPE=2?>
<?end when?>
<?end otherwise?>
<?end choose?>

This would handle 3 possible T&C templates in their sub-template.

Todd had a good comment, why are the 'call' statements not closed with an 'end call'. I did not have a good answer. Suffice to say, we handle it for you - a good if inconsistent, feature. If you want some example code, get it here.

Join the discussion

Comments ( 16 )
  • Andrew Monday, July 7, 2008
    Hi Tim,
    Found this very useful!
    I had an issue that I wasn't able to resolve using the PeopleSoft front end to do with template control fields, but was able to do it using this method.
  • Tim Dexter Monday, July 7, 2008
    Hi Andrew. I pleased to hear it - Im not just writing rubbish :0)
  • Mike Quitugua Tuesday, July 8, 2008
    Hello Tim,
    Thanks so much for your technique on subtemplates. I proved your concept on a Packing Slip document and it worked quite nicely. However, I'm having some difficulty with the Purchase Order, which is the document that started our quest and has a more immediate need. I'm using the same method as in your email to Pat Moran that worked in the Packing Slip. Here goes:
    Embedded file import of subtemplate from main template:
    Selection criteria from even-page header in main template:
    end when?>
    end when?>
    end otherwise?>
    end choose?>
    Tags in subtemplate (PO_TC.rtf):
    1. DOMESTIC. This constitutes the DOMESTIC U.S. Terms and Conditions.
    End Template
    1. GLOBAL. This constitutes the GLOBAL Terms and Conditions.
    End Template
    Finally, sample xml with value "DOMESTIC" in the tag:
    xml version="1.0"?>
    !-- Generated by Oracle Reports version -->
    The result is that only the "otherwise" condition is executed. It does not seem to evaluate the C_ORGANIZATION_ID tag at all, it simply falls to "otherwise". I suspect something is amiss with my xmlpath but I can't see where. Thanks as always for your efforts.
    Mike Q - with the Emulex Gang
  • Tim Dexter Wednesday, July 9, 2008
    Hi Mike
    You need to wrap quotes around your when conditions:
    otherwise the values are not treated as string values for the comparison
  • Mike Quitugua Thursday, July 10, 2008
    Thanks for your suggestion, Tim. Still didn't work but I have a feeling the reason is buried in my xml. I'll continue slogging it around awhile...
  • Mike Quitugua Friday, July 11, 2008
    Hello again,
    The breakdown was on our side: We had a "choose" clause for an element from a higher grouping level. That element was never properly evaluated. Your dynamic subtemplate technique works great for us.
  • Tim Friday, July 11, 2008
    Good news ... glad its working for you!
  • Robqlsla Tuesday, February 17, 2009
    Do annotations judge up you happy?
  • Sudheer Friday, March 13, 2009
    Hi Tim,
    Is there a way to import a url statement containing a dynamic .rtf file...
    OTN thread
  • Janel Tuesday, May 12, 2009
    Hi Tim,
    Hopefully a simple question, but what is the syntax for when you want to check in your choose statement if the value is null? is double quotes sufficient?
  • Shasikkumar Tuesday, June 2, 2009
    Hi Tim,
    Is it possible to have the choose, condition and corresponding call to the sub-template in a repeating group.
    The reason is - I have the AP remittance advice to be printed in two languages and the language is dependent on each supplier. So from the single print we could have more than one language as its from a payment batch which could contains many suppliers.
    So all the data fields are fine - But if I have to translate the headings and some text - Do I have to position the if conditions in my single template around the headings and constant texts or can I use sub-templates for this requirement.
  • Rajesh Thursday, October 8, 2009
    Hi Tim,
    I have converted the Remittance report to Xml. Everything worked fine even bursting also worked fine and also received the mail with pdf attachement.
    Now problem is i have created a standard template and in the standard template i have called header template to show logo's based on the organization id.
    when i run the report i am able to see the output with logo's but in the mail attachement output logo's are not showing.
    How to solve this issue. PLease help.
  • Michael Vourakis Wednesday, October 14, 2009
    Hi Tim,
    Is it possible to store the subtemplate name to a database field and call the subtemplate via the field name or a variable in a BI Publisher rtf template ?
  • Commercial Carpet Cleaner Sunday, April 11, 2010
    This is the first time I visited your blog. I am a researcher and my job is to read a lot about this topic. Sometimes I come across a website I just feel I have to thank for a valuable articles I find there, and your website made me do it too. :) Keep up the good work!
  • car seat Saturday, September 25, 2010
    Normally there is dispute and a court verdict is pending.So this means that the car will not be transferred in your name till the title is cleared.
  • Shree Friday, October 22, 2010
    Hi Tim,
    Thanks so much for posting this nice stuff. I was so confused with template, subtemplate and template, and you made it clear so quickly...
    This is very valuable resource site for like minded I guess...again thanks very much!
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.