Tuesday, December 11, 2007

BI Publisher IF statement Logical OR syntax in RTF Template

A question came through today: what is the syntax for a logical OR in a BI/XML Publisher IF statement?

The standard BI Publisher "IF" statement doesn't seem to cut it.

Lets say I want a test:

if (a=1 or a=2) and b=3 then output_my_stuff end if

I don't want to have to repeat output/logic like:
if a=1 then
 if b=3 then
  output_my_stuff
 end if
end if
if a=2 then
 if b=3 then
  output_my_stuff (again)
 end if
end if
A solution is to use form fields with an xsl if statement structure. So we have:
<xsl:if test="(A='1' or A='2') and B='3'">
 output_my_stuff
</xsl:if>
If it works use it!

4 comments:

Democracy Lover said...

I've been creating letters using BIP and the if:a=b? is very useful. I find, however, that when I use if@inlines:a=b?, the section will print even when a != b. Does the xsl if have a similar logic that actually works?

Gareth said...

Hi,

The inlines option is used to push fields onto one line, for example in a for-each group. With IF statements you need to be careful about placement, especially watch your spaces.

For a paragraph/section that you want to print or not print the structure should be:

ifxxx
Print this.
endifxxx

Note that the ifxxx and endifxxx are on their own lines, with no spaces. Then those lines won't render on your output, and you won't face problems with extraenous spaces.

If you have something like this:
"Do not print ifxxx this endifxxx."
it is not the same as:
"Do not printifxxx this endifxxx."
as there is a space after the word "print" and before the word "this", so you'll get a double space for the first option. The second is better.

Gareth

rgkn said...

Hi there,

Have you tried:

Stuff

N.B. or and and are case sensitive. The following does not work.

Stuff

Regards,

Bob

Tani said...

The method used here is very simple and easy to understand. The way of explaining is also good. As IF statement logical OR syntax looks easy but is not as simple to understand for everyone.

oracle ebs