470,863 Members | 1,363 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,863 developers. It's quick & easy.

FOP, XSLT: problems with SAX2DTM Parsing trying to convert to XSL-FO in Java

Hi there,

this is a Java-XML Question, so I am not sure whether this is the
right place, haven't found anything better ....

I try to convert a Java object to XML via SAX and let the FOP
Transformer convert that via XSLT to valid XSL-FO. So I define a
SAXReader which fires the SAX Events for the Java Object. This works
fine and the Transformation to PDF is ok.
However, I have one object which contains an XHTML String and the tags
inside that string shall be passed to the XSLT without changing them.
I have a XSL which would handle them properly and convert them to
valid XSL-FO, I just don't know how to get them thru SAX ...
My understanding is that I have to just make them fire the correct SAX
events as well. My Idea was to use a SAX Parser for that part, let it
handle the XHTML text and then continue with my other object's

code sample (will not compile, ok ;-):

class MyObjectReader{
public void parse(MyObject obj) throws SAXException {

// this works fine
handler.element("city", obj.getCity());
handler.element("street", obj.getStreet());
// now try to let a vanilla SAX parser do the xhtml
XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerce s.parsers.SAXParser");
reader.parse(new InputSource(new StringReader(obj.getXHTMLString())));


The whole thing gets used inside the FOP Transformation:

class PDFHelper{
public void convertObj2PDF(){

Driver driver = new Driver();
//Setup Renderer (output format)
TransformerFactory factory = TransformerFactory.newInstance();
// create transformer with the appropriate xsl
Transformer transformer = factory.newTransformer(new StreamSource(new
File(indir, xslFileName)));

// Setup input for XSLT transformation
// this returns a source which uses the above Reader
Source src = obj.getSource();
// Resulting SAX events (the generated FO) must be piped through to
Result res = new SAXResult(driver.getContentHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);

now what happens is that I get a NullPointerException when, inside the
XSL Transformation, after the "embedded" Parser has finished, the
reader tries to end the "xhtml" element (line:
The exception looks like this:

[12.04.05 17:07:21:531 CEST] 5dd35dd3 SystemOut O [12.04.05
17:07:21,406 CEST] util.pdf.PDFHelper - convertObj2PDF:
obj=vo.AusgangspostVO@754d754d : Error in Transformer: null
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.NullPointerException.<init>(NullPointerE xception.java:60)
at org.apache.xml.dtm.ref.sax2dtm.SAX2DTM.endElement( SAX2DTM.java:1886)
at util.pdf.EasyGenerationContentHandlerProxy.endElem ent(EasyGenerationContentHandlerProxy.java:208)
at util.pdf.EasyGenerationContentHandlerProxy.endElem ent(EasyGenerationContentHandlerProxy.java:123)
at util.pdf.AusgangspostXMLReader.generateFor(Ausgang spostXMLReader.java:159)
at util.pdf.AusgangspostXMLReader.parse(AusgangspostX MLReader.java:57)
at util.pdf.AusgangspostXMLReader.parse(AusgangspostX MLReader.java:33)
at org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DT MManagerDefault.java:493)
at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:658)
at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1129)
at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1107)
at util.pdf.PDFHelper.convertObj2PDF(PDFHelper.java:1 11)

I guess this might be bcause the SAX2DTM class used by the XSLT is not
compatible with my org.apache.xerces.parsers.SAXParser. Is this the
right direction? Can I fix the problem by using another parser?
Am I getting something terribly wrong?

I am using FOP 0.20.5 with xalan 2.4.1 and xerces 2.2.1
The app is running with jdk 1.4 and I cannot switch to newer versions
of xerces or xalan due to problems with the appserver.

Any hints are highly appreciated (even to a better suited newsgroup


Jul 20 '05 #1
1 2907

did u find any solution for this problem

even m facing same situation

Please advice what to do

Thanks in advance
Apr 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Doug Farrell | last post: by
3 posts views Thread by Justine Hlista | last post: by
6 posts views Thread by Mark | last post: by
5 posts views Thread by inquirydog | last post: by
2 posts views Thread by chris | last post: by
10 posts views Thread by Bilal | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.