Re: FOP XML->XSLT->FOP PDF Issues
On 22 Dec 2008, at 18:35, Andreas Delmelle wrote: Ok, I've started writing the actual xsl:fo style, and have a question for you guys. The xml I'm using is below, so could you point me in the best direction to get to the field data of only the current='true' version? Thanks in advance. Then inside that template/for-each, the pattern would be something like: child::versi...@current='true'] Reading your question again, maybe this is slightly inaccurate, and you actually need: child::versi...@current='true']/* to select the child elements of the version-node. Cheers Andreas - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
Re: FOP XML->XSLT->FOP PDF Issues
On 22 Dec 2008, at 18:21, Patterson, Gregory Michael wrote: Hi Gregory, Just a small FYI: this is a purely XSLT-related question, and we make it a policy of avoiding that type of question being asked on this forum. In the future, please direct those questions to the Mulberry XSLT list, which is much better suited. That said, no lack of XSLT knowledge among fop-users, so... Ok, I've started writing the actual xsl:fo style, and have a question for you guys. The xml I'm using is below, so could you point me in the best direction to get to the field data of only the current='true' version? Thanks in advance. This, of course, depends on the context, but if you have something like: ... or ... Then inside that template/for-each, the pattern would be something like: child::versi...@current='true'] More generally, starting from the root of the entire document, the XPath to select all those version-nodes in your case would be: /*/*/data/versi...@current='true'] HTH! Cheers Andreas - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
RE: FOP XML->XSLT->FOP PDF Issues
Ok, I've started writing the actual xsl:fo style, and have a question for you guys. The xml I'm using is below, so could you point me in the best direction to get to the field data of only the current='true' version? Thanks in advance. Joe Smith 000112345 s asd 999-888- a...@this.net 01 Suggestion 01 Referral 02 Yes In Person None No sd sadf3 -Original Message- From: Andreas Delmelle [mailto:andreas.delme...@telenet.be] Sent: Wednesday, December 17, 2008 2:23 PM To: fop-users@xmlgraphics.apache.org Subject: Re: FOP XML->XSLT->FOP PDF Issues On 17 Dec 2008, at 20:01, Patterson, Gregory Michael wrote: Hi > 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 Well, FOP is short for FO-Processor, so only deals with FO as input (an XML document in the XSL-FO namespace, adhering rules set out in the XSL-FO Recommendation). The XSLT specification grew out of XSL-FO, since there are many other use-cases for stylesheet transformations that have nothing to do with FO. Most of these cases are XML-to-XML/HTML, so transforming the structure of a given source XML to yield a different one, or meant for a different output target. The most notable one is HTML or XHTML, but plain text is also a possibility. You could write a second stylesheet that transforms your XML into XHTML for alternate display in a web browser, if you'd like... FOP offers the option to supply XML+XSLT as input, but this is more for users' convenience as the transformation from source XML to FO is taken care of by an XSLT processor (whichever one is available on the classpath). To answer your question (if I get it correctly): If you need PDF based on XML data, and you want to produce it using FOP, you'll indeed need to get familiar with both XSL-FO and XSLT. The benefit here is that you can use the same stylesheet for multiple output formats (PDF/PostSript/AFP/Java2D/RTF). Cheers Andreas - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org __ Information from ESET Smart Security, version of virus signature database 3699 (20081217) __ The message was checked by ESET Smart Security. http://www.eset.com
Re: FOP XML->XSLT->FOP PDF Issues
On 18 Dec 2008, at 23:45, Patterson, Gregory Michael wrote: Right, so currently I'm feeding the xml and an example style sheet in to the FOP and it's working as expected. What I'm asking is, what forms can the Style sheet be in? I already have the xsl sheet like this for other purposes: So, do I need to re-write a stylesheet similar to the second one for each doc I need to convert to PDF Even if I have full stylesheets (like the first shown) already written out. Thanks again. Short answer: yes, if you want FOP to create the PDF. The 'full' stylesheets you're referring to, they produce HTML+CSS which could obviously be converted to PDF in other ways (using Acrobat, for example). If you were to produce XHTML, then there are stylesheets around to transform that into an XSL-FO document, but HTML+CSS is not XML so cannot be fed as input to an XSLT processor (nor FOP). Cheers Andreas - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
RE: FOP XML->XSLT->FOP PDF Issues
Right, so currently I'm feeding the xml and an example style sheet in to the FOP and it's working as expected. What I'm asking is, what forms can the Style sheet be in? I already have the xsl sheet like this for other purposes: http://www.w3.org/1999/XSL/Transform"; xmlns:my-class="xalan://edu.iu.uis.eden.edl.WorkflowFunctions" version="1.0"> . . . option { background-color: #ff; color: #00; } . . . And the style I'm currently using for the FOP is like this: http://www.w3.org/1999/XSL/Transform"; xmlns:fo="http://www.w3.org/1999/XSL/Format"; exclude-result-prefixes="fo"> http://www.w3.org/1999/XSL/Format";> Project: . . . So, do I need to re-write a stylesheet similar to the second one for each doc I need to convert to PDF Even if I have full stylesheets (like the first shown) already written out. Thanks again. -Greg -Original Message- From: Andreas Delmelle [mailto:andreas.delme...@telenet.be] Sent: Wednesday, December 17, 2008 2:23 PM To: fop-users@xmlgraphics.apache.org Subject: Re: FOP XML->XSLT->FOP PDF Issues On 17 Dec 2008, at 20:01, Patterson, Gregory Michael wrote: Hi FOP offers the option to supply XML+XSLT as input, but this is more for users' convenience as the transformation from source XML to FO is taken care of by an XSLT processor (whichever one is available on the classpath). To answer your question (if I get it correctly): If you need PDF based on XML data, and you want to produce it using FOP, you'll indeed need to get familiar with both XSL-FO and XSLT. The benefit here is that you can use the same stylesheet for multiple output formats (PDF/PostSript/AFP/Java2D/RTF). Cheers Andreas - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org __ Information from ESET Smart Security, version of virus signature database 3699 (20081217) __ The message was checked by ESET Smart Security. http://www.eset.com - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
Re: FOP XML->XSLT->FOP PDF Issues
On 17 Dec 2008, at 20:01, Patterson, Gregory Michael wrote: Hi 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 Well, FOP is short for FO-Processor, so only deals with FO as input (an XML document in the XSL-FO namespace, adhering rules set out in the XSL-FO Recommendation). The XSLT specification grew out of XSL-FO, since there are many other use-cases for stylesheet transformations that have nothing to do with FO. Most of these cases are XML-to-XML/HTML, so transforming the structure of a given source XML to yield a different one, or meant for a different output target. The most notable one is HTML or XHTML, but plain text is also a possibility. You could write a second stylesheet that transforms your XML into XHTML for alternate display in a web browser, if you'd like... FOP offers the option to supply XML+XSLT as input, but this is more for users' convenience as the transformation from source XML to FO is taken care of by an XSLT processor (whichever one is available on the classpath). To answer your question (if I get it correctly): If you need PDF based on XML data, and you want to produce it using FOP, you'll indeed need to get familiar with both XSL-FO and XSLT. The benefit here is that you can use the same stylesheet for multiple output formats (PDF/PostSript/AFP/Java2D/RTF). Cheers Andreas - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
RE: FOP XML->XSLT->FOP PDF Issues
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 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: http://www.w3.org/1999/XSL/Format"; xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; exclude-result-prefixes="fo" version="1.1"> http://www.w3.org/1999/XSL/Format";> . . . Here is the error: (Location of error unknown)org.apache.fop.fo.ValidationException: Error: First element must be the fo:root formatting object. Found (
Re: FOP XML->XSLT->FOP PDF Issues
On 16 Dec 2008, at 22:35, Patterson, Gregory Michael wrote: Hi Here’s how I’m calling the FOP process. Prior to this, I have a db call to grab the stylesheet, and then I pass something like this: FOPConverter.createPDF(dom, styles, response) and the code below executes. I’m running the stylesheet from a db call right now, but still pulling the actual xml file from my local machine (trying to take it 1 step at a time =] ). If you need more, let me know. Judging from the code, I can't see how that could lead to the earlier message: 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. This seems indicative of FOP being fed the stylesheet as its input, instead of the result of the transformation. Strange thing is that the XSLT namespace does not seem to be properly processed, which I'm assuming is somehow caused by the fact that you build up the stylesheet as a DOM (?) Can you find out which XML parser and XSLT processor are used at runtime? You could also try eliminating the DOM-approach from the picture. It seems slightly redundant, since you can easily set it up like: transformerFactory.newTransformer(new StreamSource(new StringReader(xsltStyle))); No need to construct a Document, if you don't absolutely need it for other purposes. HTH! Cheers Andreas - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
RE: FOP XML->XSLT->FOP PDF Issues
Here's how I'm calling the FOP process. Prior to this, I have a db call to grab the stylesheet, and then I pass something like this: FOPConverter.createPDF(dom, styles, response) and the code below executes. I'm running the stylesheet from a db call right now, but still pulling the actual xml file from my local machine (trying to take it 1 step at a time =] ). If you need more, let me know. public static void createPDF(Document dom, String xsltStyle, HttpServletResponse response) { try { // Setup directories File baseDir = new File("C:/java/projects/rice/kew/src/main/java/edu/iu/uis/eden/edl/"); // Setup input and output files File xmlfile = new File(baseDir, "projectteam.xml"); //File xsltfile = new File(baseDir, "projectteam2fo.xsl"); // 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(xsltStyle)); // Set the value of a 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()); // Start XSLT transformation and FOP processing transformer.transform(src, res); where the 'getDocumentFromXMLString' method simply converts a string to a document object, if there's a better/easier way let me know. Heres that method: public static Document getDocumentFromXMLString(String xmlString) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xmlString))); return document; } catch (ParserConfigurationException e) { e.printStackTrace(); return null; } catch (SAXException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } } 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...@i
Re: FOP XML->XSLT->FOP PDF Issues
You need to remove "exclude-result-prefixes="fo"". I believe that causes the problem. On 16.12.2008 22:16:18 Patterson, Gregory Michael wrote: > 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: > 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"> >version="1.0"/> > > > > > > http://www.w3.org/1999/XSL/Format";> > > . > . > . > > > > 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 Jeremias Maerki - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
RE: FOP XML->XSLT->FOP PDF Issues
Are you handing this off directly to FOP or running it through another XSL processor to produce the FO output? I use the same structure in the stylesheet used to generate the FO output. The XSL processor I have for my database doesn't speak FOP, so I use it to generate an FO stylesheet that is handed off to FOP. Yes, it is a two-step process. The first element in my FO stylesheet (after the XML declaration) is http://www.w3.org/1999/XSL/Format"; xmlns:edit="edit.uri"> My technique may not be the canonical method, but it works for me. Pete Allison Marshall Space Flight Center "The universal aptitude for ineptitude makes any human accomplishment an incredible miracle." - Air Force Col. John P Stapp, first person to sustain a 40g deceleration. _ 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: http://www.w3.org/1999/XSL/Format"; xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; exclude-result-prefixes="fo" version="1.1"> http://www.w3.org/1999/XSL/Format";> . . . 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
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: http://www.w3.org/1999/XSL/Format"; xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; exclude-result-prefixes="fo" version="1.1"> http://www.w3.org/1999/XSL/Format";> . . . 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.