Search This Blog

Monday, 21 January 2013

Adding Header and footers in Template In XML


Adding Header and footers in Template

in the previous lesson we had learnt that how to create RTF. Now we are going to add Header and Footer to the existing template.
Our template which we had created in the previous lesson is shown below

For the above template we are going to add header and footer
If we want to display anything for every page then we will go to header and footer.

For that in RTF go to VIEW=>Header and Footer which is shown below







Now we are going to write some text in the Header and Footer which is shown below




Now we have to publish the report

Click on Template Builder => Preview => HTML/PDF/Excel/RTF (any format).
We can get below output





From the above output we can see that header text and footer text appeared.
For displaying any text or date or page numbers etc.. for every page we can go to Header and Footer

Alternative Method

Microsoft Word does not allow form fields in the header and footer regions of a document. If you require many or complex objects in the header or footer of your report, these regions can become difficult to read or understand. As an alternative, you can create header and footer templates in the body of your RTF template document that can then be called from the header or footer region.
To create a template within your template, simply wrap the contents of the internal template with the following tags:
<?template:internaltemplate name?>
<?end template?>
where internaltemplate name is the name you assign to the header/footer template.
Then in the header/footer region, simply enter the following syntax to call this template:
<?call:internaltemplate name?>
At runtime the contents of the internal template will render at the position of the call.
Example
Assume you have the following XML data:
<REPORT>
<COMPANY_NAME>Oracle</COMPANY_NAME>
<REPORT_NAME> Accounts Payables – Invoice Listing</REPORT_NAME>
<REPORT_DATE>1st January 2005</REPORT_DATE>
<LEGAL_TEXT>Private and Confidential</LEGAL_TEXT>
...
</REPORT>
You want the: COMPANY_NAME, REPORT_NAME, and REPORT_DATE to display in a table in the header of the report as shown in the following figure
Field Form
Field Entry
Description
Template:OraHeader
<?template:OraHeader?>
Declares a template called "OraHeader".
Oracle
<?COMPANY_NAME?>
Placeholder for the COMPANY_NAME
element.


Invoice Listing
<?REPORT_NAME?>
Placeholder for the REPORT_NAME element.
01-Jan-05
<?REPORT_DATE?>
Placeholder for the REPORT_DATE element.
End Header
<?end template?>
Closes the OraHeader template.

In the header of your template, enter the following:
<?call:OraHeader?>
At runtime the OraHeader template will be rendered in the header of each page of the document.





If-then-Else Statement In XML


If-then-Else Statement
XML Publisher supports the common programming construct "if-then-else". This is extremely useful when you need to test a condition and conditionally show a result.
Use the following syntax to construct an if-then-else statement in your RTF template:
<?xdofx:if element_condition then result1 else result2 end if?>
For example, the following statement tests the INVOICE_AMOUNT element value. If the value is greater than 5000, show the word "Higher"; if it is less than 3000, show the word "Lower"; else, show "Equal":
<?xdofx:if INVOICE_AMOUNT > 5000 then ’Higher’
else
if INVOICE_AMOUNT <3000 then ’Lower’
else
’Equal’
end if?>


Here we are using same RTF and RDF which we had used in IF statement

RTF looks like


Just give double click on Inv_Amt then we will get one pop window which is shown below

Provide proper text and Click on Add Help Text we will get another pop window which is shown below


There we have to write below code

 Which is shown below



Now we have to publish the report

Click on Template Builder => Preview => HTML/PDF/Excel/RTF (any format).
We can get below output

From the above output we can see that Inv Amt which got the result. In this way we can use IF THEN ELSE   statement

If Statement In XML


If Statement

Conditional formatting occurs when a formatting element appears only when a certain condition is met. XML Publisher supports the usage of simple "if" statements, as well as more complex "choose" expressions.
The conditional formatting that you specify can be XSL or XSL:FO code, or you can specify actual RTF objects such as a table or data. For example, you can specify that if reported numbers reach a certain threshold, they will display shaded in red. Or, you can use this feature to hide table columns or rows depending on the incoming XML data.

If Statements

Use an if statement to define a simple condition; for example, if a data field is a specific value.
1.       Insert the following syntax to designate the beginning of the conditional area.
<?if:condition?>
2.       Insert the following syntax at the end of the conditional area: <?end if?>.
For example, to set up the payable invoice register to display invoices only when the supplier or vendor is “GE Capital”, insert the syntax <?if:VENDOR_NAME=’GE Capital’?> before the supplier filed on the template
Enter the <?end if?> tag after the invoices table.
This example is displayed in the figure below. Note that you can insert the syntax in form fields, or directly into the template.

In the previous lesson we learnt that how to group records.
Our data model looks


Now generate the XML, as we know how to generate XML.

Then save the File with .xml extension in appropriate location which we are going to load this xml data to RTF.
Now we have to design Template layout
Use the Microsoft word or any word processor to generate the template layout, while saving save the document with RTF extension. Let us call this template file as if_condition_rtf.rtf.
In the previous lessons we learnt how to create table ad where we have to write column name and all those stuff.

Our XML data Looks like
Our template looks



In all Add Help Text for all Fields will show below
forvend  ---- <?for-each:G_VENDOR_NAME?>     =>PARENT GROUP
ifvend     ---- <?if:VENDOR_NAME=’AUTO HAUS’?>   =>SPECIFYING ONLY ONE VENDOR OR SUPPLIER
forinv    ----- <?for-each:G_INVOICE_DATE?>              =>CHILD GROUP
endinv  ----- <?end for-each?>                  =>CLOSING THE CHILD GROUP
endif   ----- <?end if?>    =>CLOSING THE IF CONDITION
end vend  ---- <?end for-each?>        =>closing the PARENT GROUP

 

Now we have to publish the report

Click on Template Builder => Preview => HTML/PDF/Excel/RTF (any format).
We can get below output

From the above output we can see that only ‘AUTO HAUS’ vendor invoices got in the output.
That is what ever we gave in IF Condition we will get the output which is shown above.