Tuesday, November 6, 2007

BI Publisher: Understanding the for-each tag

This should be viewed as a supplement guide to oracle standard documentation! For-each in BI Publisher (and xml in general or basic programming) causes a lot of issues for new developers or business analysts. The key to understanding xml and bi publisher is “Context.”

Vocabulary
Context: Context is used to describe where you currently at in a set of relationships. As an example: Right now your sitting down in a chair , in some room or cube, which is in building, which is in some city, some state, some country, well you get the picture.
Hierarchal Relationships: Things that exist between one more objects. An example would be a parent an child. Child is a product of the parent.
Root: is the start or the beginning of something. An example lets get to the root of the problem.
Node/Element: Basically an item of some sort. Your keys are elements of your key chain.

Let’s Get Started

The for-each tag is used to loop through and xml document. An xml document always has a root node or starting node (see bold green). All xml documents have heirachal relationships. In the example below we can see the following: an Employee is a child of dept and dept is a child of corporation. Every employee, dept and corporation have elements and these elements are typically unique to them (hence the coloring scheme).

Cont...Please scroll through

6 comments:

Fewzi said...

Excellent post? Thank you for this useful explanation of the way to navigate through the hierarchy and the notion of context (../../).

Anonymous said...

thankyou it is very helpfull

Alicia said...

Is there a way to advance through the XML using the for-each, but display the results on the same line instead of incrementing the displayed results each time?

Ike Wiggins said...

Use a predicate in the for-each.

Try for-each: xmlfield[1]

Or alternatively do this for every field that's in the for-each

Anonymous said...

Thanks for the info. I have another question. What if you a group is repeating twice because the outer group gives a duplicate record. I cannot modify the query and hence need to avoid the duplicate rows in RTF template only. How do I do this?

Ike Wiggins said...

Group the outer group to remove the duplicate or add an xpath predicate position()=1