ReportListener HTML Foundation Class
HtmlListener provides the Report Output Application's default implementation of ListenerType 5 (HTML output) and Genhml.prg's default implement of HTML output from report and label files (frx and lbx tables).
Category | Reporting |
---|---|
Default Catalog |
Visual FoxPro Catalog\Foundation Classes\Output\Report Listeners |
Class |
HtmlListener |
Base Class |
ReportListener |
Class Library |
_REPORTLISTENER.vcx |
Parent Class |
XmlDisplayListener (ReportListener XML Display-Style Foundation Class) |
Remarks
HtmlListener leverages XmlListener's ability to apply an XSLT transformation document to the base VFP Report XML document format automatically at the conclusion of a report run. For information on XmlListener's XSLT processing capabilities, see ReportListener XML Foundation Class.
HtmlListener adds no new properties or methods to its parent class, XmlDisplayListener. It sets the output file extension to "HTM"
and its ApplyUserTransform property to .T.
and augments the internal XmlListener method, getDefaultUserXslt, to supply an appropriate XSLT transformation document for HTML production.
The custom XSLT document included in HtmlListener handles all the details of reading the VFP-RDL for your original report or layout information, and reproduces this layout in HTML. Your user's printer at run time may have a different printable page size than the printer for which the report was originally rendered, and your user's browser may also add headers, footers, and margins, into this page layout. As a result, you should not rely on this format to print with appropriate page breaks from the browser; it is designed primarily for page display.
Tip
You can use the RANGE clause on the REPORT FORM command to provide HTML data on a page-by-page basis, so it will print properly from the browser. Note that HtmlListener's default XSLT document supports the RANGE clause only for single reports, not multiple reports using the NOPAGEEJECT capability. Without RANGE, HtmlListener's default XSLT supports multiple reports in a single HTML document.
If you want exact, printable page copies, you can use the ReportListener class's OutputPage method to provide image files of individual report pages for printing purposes. See the ReportListener Object for more information.
However, you are not limited to faithful reproduction of the original report design. You can replace the default XSLT transformation with any other rendering of the original report data that suits you, customizing a single report result for different users on different target devices. Simply store a reference to a different XSLT transformation document into the XsltProcessorUser property. The sample code in ReportListener XML Foundation Class shows you how to change the contents of the document.
Example
This example sets HtmlListener's target output file and precision of numeric coordinates, and specifies that any image files rendered in the report should be copied to a subdirectory relative to its output file. This is an appropriate approach if the report will be published on a web server.
Note
This example is designed to be used in a distributed application, so it does not include a path to the FFC class library. If you would like to run it as a program from the command line, un-comment the SET PATH statement.
After running a report, the example brings up the HTML output in a Visual FoxPro editing window for verification and then displays the current XsltProcessorUser document contents as text on the Visual FoxPro screen, for your reference.
Tip
If you examine the contents of the XSLT document closely, you find that theStylesheet.xml property still shows the pre-compilation numberPrecision default value, 5
, and the default values for all other parameters in this XSLT document. For example, externalFileLocation is a parameter in the XSLT document, and the value you assign in the example, ".\images"
, does not show in the Stylesheet.xml contents. XMLListener's applyXSLT method applies parameters' runtime values to the compiled Stylesheet instance, just before it applies the compiled transform document to your source XML.
LOCAL oHtml
* SET PATH TO (HOME() + "FFC") ADDITIVE
oHtml = NEWOBJECT("HtmlListener","_reportlistener.vcx")
oHtml.targetFileName = "c:\temp\myOutput.htm"
* The following lines of code set the precision of coordinates
* of most individual layout items as a number of decimal places
* (the XSLT's coordinates are in inches).
* The default number of decimal places is set in the XSLT to 5,
* but here the value is set to 6:
oHtml.xsltParameters = CREATEOBJECT("Collection")
oHtml.xsltParameters.Add(6,"numberPrecision")
* The following directory must exist *before*
* you assign the next property:
IF NOT DIRECTORY("c:\temp\images")
MD c:\temp\images
ENDIF
* Assignment of the image directory as
* a relative reference ensures
* appropriate src attributes in the
* HTML document:
oHtml.externalFileLocation = ".\images"
oHtml.copyImageFilesToExternalFileLocation = .T.
REPORT FORM ? OBJECT oHtml
MODIFY FILE (oHtml.targetFileName)
ACTI SCREEN
? oHtml.XsltProcessorUser.Stylesheet.Xml
See Also
Reference
Visual FoxPro Foundation Classes A-Z
Genhtml.prg
ReportListener XML Display-Style Foundation Class
Concepts
Guidelines for Using Visual FoxPro Foundation Classes