X

An Oracle blog about BI Publisher

  • RTF
    November 19, 2007

Conditional Rows and Columns

Back from OOW and fighting a cold from all that 'sea level' air - give me the moutains any day. I dont really mean that - I lived by the ocean until we left the UK in '99 - I miss it, but standing atop Pikes Peak is a sight to behold. I promised normal service when I got back from crazy town, this morning there was a question on the forum asking how to achieve conditional rows and columns. I have admit I thought I had covered that here or in the documentation ... I can not find it so here goes.



Conditional Rows



This is pretty straightforward and later releases of the template builder will help you achieve even more easily. Basically you need an 'if' statement that will cover the complete row.



ConditionalRow1:



Notice the 'C' field, this contains the conditional code:



<?if@row:number(SAL)>2000?><?attribute@incontext:color;'red'?><?end if?>



see the '@row' thats going to apply the condition to the whole row for us. You can either hand code it or as I mentioned the template builder will do it for you. It provides a friendly dialog for simple conditions - if you have more complex requirements then you are going to have to get your feet wet or hands dirty in the code.



ConditionalRow:



The '@incontext' is a useful addition to the 5.6.3 release shortening code requirements further to update attributes, in this case the color.



The above condition will highlight the text red for the whole row where an employee has a salary greater than 2000.



ConditionalRow2:



Conditional Columns



This runs along similar lines to rows ie we have an '@column' command. Sadly the template builder cannot help you here ... yet. But the code is not tough to write. I have written something a little more interesting for the conditional column formatting. I have grouped the employees by department and then added some conditional logic to hide the Job column if the department name is 'Accounting'



ConditionalColumn:



Notice the 'CC' fields, I need one for the column header and the data cell, the contents are simple:



<?if@column:DNAME !='ACCOUNTING'?><?end if?>



 The @column defines the extent of the conditional statement ie just to the column, when executed we get the following:



ConditionalColumn2:



notice the missing Job column.



Now I have used some simple conditions you can of course get pretty complex in the logic, you're limited only by your imagination and your XSL knowledge, there by hangs a tale - you got questions get to the forum, Im there in Colorado mornings and late evenings. Get the template and data here.

Join the discussion

Comments ( 10 )
  • Brian Batten Thursday, July 17, 2008
    Can conditional formatting be done based on comparing two field values as opposed to comparing a field value against a number.
    Eg instead of 2000?>
    there is another field called MIN_SAL set to 2000 that can be at the same level or higher in the xml tree.
    I have tried =2000?> ..... which works
    but when I try
    =MIN_SAL?> ..... it displays all rows regardless of whether the SAL is greater than 2000 or not.
    Regards,
    BB.
  • Tim Thursday, July 17, 2008
    Hi Brian
    You may need to clarify where the MIN_SAL is coming from. Assuming you are in a loop when showing the SAL value e.g. just using
    if:SAL > MIN_SAL is not enough - unless MIN_SAL is at the same level as SAL, which I doubt. You need to either use .//MIN_SAL to find the first instance of MIN_SAL frm the top of the tree or be specific /ROOT/MIN_SAL ie provide the complete path to the MIN_SAL value.
    You might also wrap number() around the values
    number(SAL) > number(/ROOT/MIN_SAL)
    this will force a numeric comparison rather than a string one or remove any hope that the XSLT engine will infer a numeric one.
    Tim
  • Robeplcq Tuesday, February 17, 2009
    I am promoting my blogs from one end to the other puticipatation in odd gossip forums and, unfortunately, most annotations or responses I am getting on these boards, not in a small-brained while in my blog refereements …
  • Nagashree Thursday, February 19, 2009
    Is there a way to maintain the table size constant even though we hide the column? In xsl fo, there is a attribute 'visibility' for fo:table-column, but I am unable to use it conditionally through BI-publisher. Appreciate your help in this regard
  • Evris Thursday, May 21, 2009
    I tried the following directly from the manual

    lightgray

    It only works on PDF. Is there a restriction to the other formats (HTML, RTF)?
    Thank you in advance
  • Evris Thursday, May 21, 2009
    Sorry, something' gone missing from the code
    "
    name="background-color"
    xdofo:ctx="incontext">lightgrayribute>"
  • Sagar Junnu Monday, September 14, 2009
    Thank you for the tip on conditional formatting. it did a great deal of help in catering for one of my BI Publisher reports
  • amitmah Monday, November 2, 2009
    Hi
    I have some variables in my report, and depending upon variable values i would like to hide some columns.
    How can i find variable value in this .rtf template?
    Thanks & Regards
    ami
  • never fail list building system Sunday, August 22, 2010
    I'm grateful for you because of this wonderful written content. You definitely did make my day :
  • Georgetta Rehling Sunday, September 26, 2010
    Going to bed with a bottle of milk or juice is the most common cause.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.