Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > FOP and XSLT <xsl:import> issue

Thread Tools

FOP and XSLT <xsl:import> issue
Posts: n/a

I am trying to build a PDF page from an XML and an XSL:FO document from
inside a servlet. My XSL:FO is using <xsl:import> to reference
additional stylesheets for style as well as other support templates.
These support stylesheets are in the same directory as the master
XSL:FO doc.

My parent XSL:FO doc runs fine when I run it through a renderer like
XMLSpy, but when I run the transform from a servlet, my PDF document is
empty. I have traced this problem to my <xsl:import> statement which I
originally had using a relative path. If I change the relative path to
an absolute path, the thing runs perfect. However, using absolute paths
is not an option for me since I need the same code to work on both
Windows and UNIX.

Any suggestions on this? Here is some sample code:

JSP which calls FOP:
<%@ page import = "*, javax.xml.transform.*,*, org.xml.sax.InputSource,
org.apache.fop.apps.*, org.apache.fop.messaging.*," %>


String xmlBase = "/WEB-INF/XML/";
String detailXML = (String)request.getAttribute("DETAIL_XML");
ServletContext context = getServletContext();

String origin = (String)request.getParameter("origin");
String navigation = origin.toUpperCase();

String fileName = "ViewMessages.pdf";
response.setContentType( "application/pdf" );
response.setHeader("Content-disposition", "attachment; filename="
+fileName );

String styleSheet = "ViewPDFDetails"; xslURL = context.getResource(xmlBase + "xsl/" +
styleSheet + ".xslt"); pdfOutput = new; interimOut = new ;

InputStream xslInputStream = ( InputStream )xslURL.getContent();

StringBufferInputStream xmlInputStream = new StringBufferInputStream(
detailXML );

StreamSource xmlSource = new StreamSource(xmlInputStream);
StreamSource xslSource = new StreamSource(xslInputStream);

TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xslSource);

transformer.transform(xmlSource, new StreamResult( interimOut ));

String foOutput = interimOut.toString();

Driver driver = new Driver(new InputSource(new StringReader(
foOutput)), pdfOutput);

ByteArrayInputStream bais = new ByteArrayInputStream(
pdfOutput.toByteArray() ); bis = new
bais );

int bit = 1024;
try {
while ((bit) >= 0) {
bit =;
}catch(Exception e){


}catch(Exception e){}

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlnsalan=""

<xsl:import href="./styles.xsl" />

<xsl:template match="/">

Reply With Quote
R.F. Pels
Posts: n/a
      04-05-2005 Removed) wrote:

> an absolute path, the thing runs perfect. However, using absolute paths
> is not an option for me since I need the same code to work on both
> Windows and UNIX.
> Any suggestions on this?

Simple solution: make sure that your working directory is set to the origin
of the template. Other solution: require that there is a configuration file
located at a known good location, load the necessary properties from there.
For Windows machines, that would be the system directory, for UNICES that
would be a subdirectory of the /etc hierarchy. Query the system properties
to find out on what architecture you are running.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems running Apache FOP: fatalError Pablo Java 0 03-28-2007 02:31 PM
How to convert XML to XSLT & XSL-FO to be used by FOP ? Java 1 03-21-2007 12:34 PM
FOP, XSLT: problems with SAX2DTM Parsing trying to convert to XSL-FO in Java Jens Mueller XML 0 04-12-2005 04:06 PM
newbie questions concernig XSL/XSLT and FO/FOP (sorry, long) DV XML 2 04-02-2004 02:31 AM
weird links in PDF from XML and xslt using FOP Jurrie XML 0 10-06-2003 08:26 AM