Java Program -CSSToXSLFOFilter- blank output

Help
ReedH
2012-10-25
2012-12-07
  • ReedH

    ReedH - 2012-10-25

    I am trying to create a Java program that converts an html report to pdf. I am trying to use CSSToXSLFO as part of this. Right now I am just trying to get started on this by simply converting an XML to a XSL FO as in 5.2.1 Example 1. I have not been able to get anything but a blank output file and I cant seem to figure out why. Here is the code, any suggestions?

    public class HTMtoXSLFO {
       
        public static void
            main(String args) throws Exception {
                   
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(true);
            CSSToXSLFOFilter filter = new CSSToXSLFOFilter(new File("C:\\Users\\reed henderson\\Documents\\NGP 2013 HARNESS\\report.xml").toURL(),factory.newSAXParser().getXMLReader());
            TransformerHandler handler =((SAXTransformerFactory)TransformerFactory.newInstance()).newTransformerHandler();
            handler.setResult(new StreamResult(new File("C:\\Users\\reed henderson\\Documents\\NGP 2013 HARNESS\\test.fo")));
            filter.setContentHandler(handler);
            filter.parse(new InputSource(new FileInputStream("C:\\Users\\reed henderson\\Documents\\NGP 2013 HARNESS\\report.xml")));
            }
    }

     
  • Werner Donné

    Werner Donné - 2012-10-26

    Hello,

    There should be at least one element with the "region" property set to "body". In the case of XHTML this is set in the User Agent style sheet, but if you use another XML-vocabulary you have to set it yourself.

    Best regards,

    Werner.

     
  • ReedH

    ReedH - 2012-10-26

    Thanks for the fast reply!

    For now I am just trying to convert an XML file. If I run this on an xhtml file it just errors out…but I would expect that since its not an XML file. but I dont want to mess with that yet.

    I added an element with a "region" property set to "body" but that does not seem to have helped. Here is my xml file I am trying to convert., maybe there is something else wrong with it?

    report.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <report region="body">
    <report title="Harness BOM Report">
       <reportmodule title="">
          <resultsetheader title="DESIGN"/>
          <resultsetheader title="DESCRIPTION"/>
          <resultsetheader title="REV"/>
          <resultsetheader title="RELEASE LEVEL"/>
          <resultset>
             <result>P92-5256</result>
             <result>HARN - ENG 2013 MX13 NGP</result>
             <result>A</result>
             <result>In Work</result>
          </resultset>
       </reportmodule>
       <reportmodule title="">
          <groupBy title="groupingKey"/>
          <resultsetheader title="VAR"/>
          <resultsetheader title="TYPE"/>
          <resultsetheader title="REFDES"/>
          <resultsetheader title="ZONE"/>
          <resultsetheader title="HOUSING"/>
          <resultsetheader title="QTY" accumulateContent="+" type="float"/>
          <resultsetheader title="UNIT"/>
          <resultsetheader title="PACCAR PART NUMBER"/>
          <resultsetheader title="SUPPLIER NAME"/>
          <resultsetheader title="SUPPLIER PART NUMBER"/>
          <resultsetheader title="DESCRIPTION"/>
          <resultsetheader title="MATERIAL"/>
          <resultsetheader title="groupingKey" invisible="true"/>
          <resultset>
             <result>N/A</result>
             <result>Connector</result>
             <result>P125C</result>
             <result>G21</result>
             <result>&lt;p&gt;&amp;nbsp;&lt;/p&gt;</result>
             <result>1.0</result>
             <result>Each</result>
             <result>P20-1288</result>
             <result>DELPHI</result>
             <result>13602480</result>
             <result>3-WAY GT 150-PLUG</result>
             <result>PLST</result>
             <result>A:P125C:A:Connector:P20-1288</result>
          </resultset>
       </reportmodule>
    </report>
    </report>


    Thanks again,

    Reed

     
  • Werner Donné

    Werner Donné - 2012-10-26

    Hi Reed,

    You shouldn't put the attribute "region" on the element, but assign the propery "region" to that element in a stylesheet. You can include the stylesheet as decribed in section 2.1 of the manual.

    Best regards,

    Werner.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks