XSL Stylesheet component example: Creating a PDF report
You can use a USoft XSL Stylesheets component to instantly create a PDF report from data retrieved from a Rules Engine.
If the component source is an XSL stylesheet that produces XSL-FO formatting objects and has the following top-level namespace declaration:
xmlns:fo="http://www.w3.org/1999/XSL/Format"
then, at the time when you have the component checked, extra methods are automatically generated that allow you to export the result of the stylesheet transformation to PDF or HTML; notably:
Method Name
Description
CREATEBASE64PDF
Converts XSL-FO XML to PDF
CREATEPDFFILE
Converts XSL-FO XML to PDF
Writes the result to a file
CREATEHTML
Converts XSL-FO XML to HTML
CREATEHTMLFILE
Converts XSL-FO XML to HTML
Writes the result to a file
The PDF generator uses version 1.0.5 of the Fonet.Standard Nuget. This nuget version is installed automatically with USoft.
Example
This simple report example has 2 blocks of data. The first block is a data grid that contains a summation (Sold) for each record. The second block is just a grand total (Total Sales) placed at the bottom of the report.
In this example, not only the formatting objects that determine the report composition, but also the source data that populate the report are provided by the XSL code. With this design choice, you have no need for specific input XML to apply the XSL to. For this reason, the XSL is applied to a dummy <root/> XML document.
You can apply XSL and then convert to PDF all in 1 go. Do this by nesting the 2 operations in a single statement of this type:
INVOKE PDF_report_writer.createpdffile WITH SELECT '<root/>' xml , 'c:\temp\tours_sales.pdf' dest_file
Follow these steps to create this solution:
In USoft Definer, double-click the XSL Stylesheets node in the Model and Rules Catalog: or choose Define, RDMI, Dotnet Components, XSL Stylesheets from the main menu.
Name the component "PDF_REPORT_WRITER”. In the Program Source field, specify the XSL transformation that produces the XSL-FO formatting objects you want as input for the PDF report. This example XSL-FO is in the next section.
Press Check. See that the checker produces, among other methods, the CREATEPDFFILE method. Save work.
You are now ready to call the component by the INVOKE statement shown above.
This stylesheet gets data for the first area through a Logical View called PDF_TOUR. In this case, the summation (the Sold column) is performed by the Logical View and displayed by the XSL:
select t.tour_id , t.destination , t.tour_type , t.start_date , t.return_date , sum( r.price ) sold from tour t , reservation r , traveller tr relate t "FOR WHICH IS MADE" r , r "IS MADE FOR" tr group by t.tour_id , t.destination , t.tour_type , t.start_date , t.return_date
This stylesheet gets data for the grand total at the bottom of the report through a Logical View called PDF_TRAVELLER. In this case, the Logical View is a preparation for the summation, and the actual SUM() operation is performed in the XSL stylesheet:
select tr.res_id , tr.person_id , r.price from reservation r , traveller tr relate r "IS MADE FOR" tr