You are on page 1of 6

<CORPORATION>

<NAME>Vision</NAME>
<DEPT>
<DEPT_NAME>IT</DEPT_NAME>
<EMPLOYEE>
<EMPNO>6</EMPNO>
<ENAME>Rich Walker</ENAME>
<JOB>CLERK</JOB>
<SAL>100</SAL>
</<EMPLOYEE>>
<EMPLOYEE>
<EMPNO>5</EMPNO>
<ENAME>Russ Kepel</ENAME>
<JOB>CLERK</JOB>
<SAL>100</SAL>
</EMPLOYEE>
<EMPLOYEE>
<EMPNO>8</EMPNO>
<ENAME>Helbe Korth</ENAME>
<JOB>CLERK</JOB>
<SAL>100</SAL>
</EMPLOYEE>
</DEPT>
<DEPT>
<DEPT_NAME>Accounting</DEPT_NAME>
<EMPLOYEE>
<EMPNO>1</EMPNO>
<ENAME>Ike Wiggins</ENAME>
<JOB>CLERK</JOB>
<SAL>100</SAL>
</<EMPLOYEE>
<EMPLOYEE>
<EMPNO>2</EMPNO>
<ENAME>Heike Elder</ENAME>
<JOB>CLERK</JOB>
<SAL>100</SAL>
</EMPLOYEE>
</DEPT>
</CORPORATION>

Overview of for-each

Example 1: Get Depts


This statement will loop through all of the DEPT nodes twice (there are only two dept nodes).

<?for-each:DEPT?><?DEPT_NAME?><?end for-each?>

DEPT
For-Each DEPT_NAME End-For-Each

It will produce the following output:

DEPT
IT
Accounting
Example 2: Get dept/employee
Now this is where were going to reference the vocabulary above. Employees are available in the
context of the current element or node dept. So you can access those elements but it will be in the
context of the current node, which only has two elements to loop through.

<?for-each:DEPT?><?DEPT_NAME?><?ENAME?><?end for-each?>

DEPT Employee Name


For-Each DEPT_NAME ENAME End-For-Each

It will produce the following output:

DEPT Employee Name


IT Rich Walker
Accounting Ike Wiggins

Example 3: Get all the depts and employee


Seems confusing, huh. You would have expected to see Russ, Heike, Helbe, etc. The parser got the
first employee for each dept.

If we wanted to drill down in employee’s we would need to make sure were in the right context and
to tell the parser there’s more elements there. In order to do this, we need to do another for-each
loop. This tells xml parser the following. For each dept, get each dept and for each employee get
there name too and in that order.

<?for-each:DEPT?>
<?DEPT_NAME?>
<?for-each: EMPLOYEE?>
<?ENAME?>
<?end for-each?>
<?end for-each?>

DEPT Employee Name


For-Each DEPT_NAME For-Each ENAME End-For-EachEnd-For-Each

We get the following output:

DEPT Employee Name


Rich Walker
Russ Kepel
Helbe Korth
Ike Wiggins
Heike Elder
Example 4: Fix missing dept
We can see that dept somehow disappeared. This is can be caused by nesting for-each statements in
the same row cell. To fix this will use the ../ syntax.

<?for-each:DEPT?>
<?../DEPT_NAME?>
<?for-each: EMPLOYEE?>
<?ENAME?>
<?end for-each?>
<?end for-each?>

DEPT Employee Name


For-Each DEPT_NAME For-Each ENAME End-For-EachEnd-For-Each

We get the following output:

DEPT Employee Name


IT Rich Walker
IT Russ Kepel
IT Helbe Korth
Accounting Ike Wiggins
Accounting Heike Elder

Example 5: Get all corporation, dept and employees


Now if we are able to go down the xml tree from dept to employee shouldn’t we be able to go
up? Yep, we already did with dept. Will use he following syntax achieves that: ../ or //

Note: // this is not in-context command, it will find the first element in the document that
matches. This isn’t a problem if there is only one element. We will be doing that in this
example. Also, if you wanted to find the first element in the current context you could do .//

For example : If we want to display main group elements in the sub group like “ENAME” in “DEPT”
group. We have to place the ../../ before the tag (../../ENAME)

<?for-each:DEPT?>
<?//NAME?>
<?../DEPT_NAME?>
<?for-each: EMPLOYEE?>
<?ENAME?>
<?end for-each?>
<?end for-each?>

Corporation DEPT Employee Name


For-Each NAME DEPT_NAME For-Each ENAME End-For-EachEnd-For-Each

We get the following output:

Corporation DEPT Employee Name


Vision IT Rich Walker
Vision IT Russ Kepel
Vision IT Helbe Korth
Vision Accounting Ike Wiggins
Vision Accounting Heike Elder
There are some ways to modify for-each statements. In most cases they are as follows:

For-each@section: @section Gives the data in new page


For-each@cell
For-each-group: field1; field2;
For-each-group:current-group();field3;
For-each-group@column

Example 6:

<?split-by-page-break:?>

We can use split-by-page-break , how many times we want in a single layout.


We have to use this tag exactly before end tag of any group
Don’t use the split-by-page-break in the same line of data row.

Example 7:

<?xdoxslt:sysdate()?>
<?xdoxslt:sysdate('DD/MM/YY HH:MI:SS')?>

To get the Date in RTF Report, For Displaying Current System Date in Layout we have to use above
Tag.

Example 8:

<?for-each@section:G_DEPTNO?>

Use @section to split the page at every deptno level.


The problem with @section is if we don’t have data the output will not open.
And we can’t use @section more than once per a layout.

Example 8:

url:{concat('${OA_MEDIA}','/',IMAGE_FILE)}

For this you have to follow below steps:


1. Insert a dummy image in your template.
2. In Microsoft Word's Format Picture dialog box select the Web tab. Enter the following syntax in
the alternative text region to reference the image URL:
url:{'http://image location'}

For example, enter: url:{'http://www.oracle.com/images/ora_log.gif'}

Example 9:

<?start@last-page:body?> <?end body?>

If you want to display the total in last page use this command.
Example 10:

<?if@row:SAL > 3000?>


<xsl:attribute xdofo:ctx="incontext" name="background-color">red

The colour will apply to entire row by using “@row” attribute.


If you remove the “@row” the colour will apply to that single column only.
The Xdofx:ctx has two values 1.incontext 2.block

Example 11:

<?if:SAL > 2500 ?>


<?end if?>

If you want to hide the Rows use this command in Group level

Example 12: To show page wise totals

<?init-page-total: pst?>
<?add-page-total:pst;'SAL'?>
<?show-page-total:pst;'C9G990D00';'(C9G990D00)'?>

If you are using sum(SAL) function in the any rtf file, if at least one SAL field contains salary null, the
output will not generated & it will give an error.
To get a correct result you have to handle null columns like below:

sum(SAL[.!=’’])

Example 13:

 Create a variable
<?xdoxslt:set_variable($_XDOCTX, 'V_NUM', 0)?>

 Incremet / decrement variable


<?xdoxslt:set_variable($_XDOCTX, ‘V_NUM’, xdoxslt:get_variable($_XDOCTX, ‘V_NUM’) + 1)?>

 Display variable
<?xdoxslt:get_variable($_XDOCTX, 'V_NUM')?>

<?for-each-group:CD;COUNTRY?>

<?for-each-group:current-group();YEAR?>

<?for-each:current-group()?>

<?end for-each?>

<?end for-each-group?>

<?end for-each-group?>
Number Formatting

<?xdoxslt:xdo_format_number_l(100000,'999G999D99','EN-us')?>

Output:- 100,000.00

<?xdoxslt:xdo_format_number_l(100000,'999G999D99','DE-de')?>

Output:- 100.000,00

Repeating the Output Based on the String Length

<?xml version="1.0" encoding="WINDOWS-1252" ?>


<juvva>
<test>kranthi</test>
</juvva>

You might also like