Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Generating HTML pages from XSL:FO and XML

    Hi,

    I have a XSL:FO file which is used to create PDF and it uses XML for data population. I want to know that is there any way to use the same XSL:FO file to create HTML pages. I need to have the HTML pages with same formatting as my PDFs have and I don't want to waste time creating new HTML pages.

    I have tried creating HTML using the FopFactory which I use for creating PDF but it takes MimeConstants as input and is not working for text/html MimeType.

    Any help would be highly appreciated.

    - Sonika

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    FopFactory? MimeConstants? What language is this?

    Source code samples strongly recommended.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am using the following class which takes XML and XSL:FO files as input and generated a PDF:

    import java.io.File;
    import java.io.OutputStream;

    import org.apache.fop.apps.*;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.sax.SAXResult;
    import javax.xml.transform.stream.StreamSource;

    public class GeneratePDf {
    public static void main(String[] args) {
    try {
    File filePDFfile = new File(strOutputfilePath);
    File fileXMLFile = new File(strXMLFile);
    File fileXSLFile = new File(strXSLFile);
    System.out.println("filePDFfile = " + filePDFfile.getAbsolutePath());

    // configure fopFactory as desired
    FopFactory fopFactory = FopFactory.newInstance();

    FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    // configure foUserAgent as desired

    // Setup output
    OutputStream out = new java.io.FileOutputStream(filePDFfile);
    out = new java.io.BufferedOutputStream(out);

    try {
    // Construct fop with desired output format
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
    foUserAgent, out);

    // Setup XSLT
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory
    .newTransformer(new StreamSource(fileXSLFile));

    // Set the value of a <param> in the stylesheet
    transformer.setParameter("versionParam", "2.0");

    // Setup input for XSLT transformation
    Source src = new StreamSource(fileXMLFile);

    // Resulting SAX events (the generated FO) must be piped through
    // to FOP
    Result res = new SAXResult(fop.getDefaultHandler());

    // Start XSLT transformation and FOP processing
    transformer.transform(src, res);
    } finally {
    out.close();
    }
    System.out.println("SUCCESS");
    } catch (Exception e) {
    System.out.println(e.toString());
    e.printStackTrace();

    }
    }
    }


    This doesn't help me to craete HTML from XSL:FO file. I have tries using the XSLT file downloaded from http://www.renderx.com/tools/fo2html.html
    But that file gives me only basic formatting.
    Last edited by sonika_nitj; 08-27-2008 at 06:23 AM. Reason: Error in code corrected


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •