For reference, I finally got this resolved by using the approach below:
                // configure fopFactory as desired
                FopFactory fopFactory = FopFactory.newInstance();
                FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
                // configure foUserAgent as desired

                // Setup output
                OutputStream out =  response.getOutputStream();
              response.setContentType("application/pdf");

                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 
DOMSource(getDocumentFromXMLString(xsltStyle)));
                    Transformer transformer = factory.newTransformer(new 
StreamSource(new StringReader(xsltStyle)));
                    //Transformer transformer = factory.newTransformer(new 
StreamSource(xsltStyle));

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

                    // Setup input for XSLT transformation
                    //Source src = new StreamSource(xmlfile);
                    Source src = new DOMSource(dom);

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

                    // Start XSLT transformation and FOP processing
                    transformer.transform(src, res);
                } finally {
                    out.close();
                }

Thanks to everyone for their suggestions and help with this.
I do have a question (it's simple I think): Looking at the example xsl sheets, 
they utilize the xsl:fo funcationality and tags heavily, but I thought that I 
was told (or read) somewhere that a regular xslt stylsheet could be used as 
well. Is that the case, or will I need write specially formatted xsl:fo styles 
for each form I need to generate a pdf from? Thanks

-Greg

From: Griffin,Sean [mailto:sgrif...@cerner.com]
Sent: Tuesday, December 16, 2008 4:26 PM
To: fop-users@xmlgraphics.apache.org
Subject: RE: FOP XML->XSLT->FOP PDF Issues

Greg,
Can you show how you are calling into FOP?  Through the command-line or 
embedded in your Java app?  FOP can take either an XSL-FO document or an 
XML/XSLT document pair that generates the XSL-FO and then turns around and 
processes that FO.  While I'm guessing a bit here, this error seems like 
something that would happen if you were using the XSL-FO input example but 
passing in an XSLT stylesheet instead of an XSL-FO doc.

For example, to pass XML/XSLT into FOP do something like this (taken from the 
FOP examples):

                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer(new 
StreamSource(xsltfile));
                Source src = new StreamSource(xmlfile);
                Result res = new SAXResult(fop.getDefaultHandler());
                transformer.transform(src, res);

But to just pass in an FO doc:

            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            Source src = new StreamSource(fo);
            Result res = new SAXResult(fop.getDefaultHandler());
            transformer.transform(src, res);

Something else to try is to just take FOP out of the equation and do a simple 
XSLT transformation.  You would expect an XSL-FO document as the result of the 
transformation, and if that doesn't happen then that would point you to why FOP 
is choking.

Sean

From: Patterson, Gregory Michael [mailto:grpat...@indiana.edu]
Sent: Tuesday, December 16, 2008 3:16 PM
To: fop-users@xmlgraphics.apache.org
Subject: FOP XML->XSLT->FOP PDF Issues

Hello,
I'm having some trouble getting the FOP to properly use an xslt stylesheet.
I am getting a ValidationException saying I need to put fo:root at the top.
My first element is an xsl element, but the first fo: element is
fo:root.  This is exactly the same format as the examples in the fop
examples packages.

In my case, I need to pull the appropriate xsl from a database, and
below is what I'm getting back:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet 
xmlns:fo="http://www.w3.org/1999/XSL/Format"; 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; exclude-result-prefixes="fo" 
version="1.1">
  <xsl:output indent="yes" method="xml" omit-xml-declaration="no" 
version="1.0"/>
  <xsl:param name="versionParam" select="'1.0'"/>
  <!-- ========================= -->
  <!-- root element: projectteam -->
  <!-- ========================= -->
  <xsl:template match="projectteam">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
      <fo:layout-master-set>
.
.
.



Here is the error:
(Location of error unknown)org.apache.fop.fo.ValidationException: Error: First 
element must be the fo:root formatting object. Found (Namespace URI: "", Local 
Name: "stylesheet") instead. Please make sure you're producing a valid XSL-FO 
document
Finished.

If you'll notice, the first fo element is fo:root, but I do have other things 
(required afaik) before it.
Thanks in advance for any help.
-Greg
________________________________
CONFIDENTIALITY NOTICE This message and any included attachments are from 
Cerner Corporation and are intended only for the addressee. The information 
contained in this message is confidential and may constitute inside or 
non-public information under international, federal, or state securities laws. 
Unauthorized forwarding, printing, copying, distribution, or use of such 
information is strictly prohibited and may be unlawful. If you are not the 
addressee, please promptly delete this message and notify the sender of the 
delivery error by e-mail or you may call Cerner's corporate offices in Kansas 
City, Missouri, U.S.A at (+1) (816)221-1024.

Reply via email to