Tuesday 24 December 2013

If Statement in XML Publisher

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.

1 comment: