473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
attributes:

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

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

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

}
}

The whole thing gets used inside the FOP Transformation:

class PDFHelper{
public void convertObj2PDF(){

Driver driver = new Driver();
//Setup Renderer (output format)
driver.setRenderer(Driver.RENDER_PDF);
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
FOP
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:
handler.endElement("xhml");).
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
java.lang.NullPointerException
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
....)

Regards

Jens
Jul 20 '05 #1
1 3075
Hi

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug Farrell | last post by:
Hi all, I'm trying to use the 4Suite xml/xsl tools to transform some XML data into HTML. I'm using some examples from the O'Reilly book "Python and XML" and things are blowing up. Here is the...
2
by: Geathaa | last post by:
Hi everyone, I want to transform a xml document containing the description of a menu tree to HTML. The MenuTree XML contains the target URL for each tree node. Some URL's contain parameters...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
3
by: Justine Hlista | last post by:
I'm using xalan-j_2_6_0 and trying to get an example from Michael Kay's book to work: <xsl:template match="/"> <xsl:variable name="rainbow"> <color>red</color> <color>blue</color>...
6
by: Mark | last post by:
Hello, I'm having problems with an XSLT template I'm developing. I have a date in an odd format which I'm trying to convert into something more readable. The original date is in the format...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
12
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
2
by: chris | last post by:
Hi there, I create an XML file from a dataset like this: System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(FILENAME); dsUserData1.WriteXml(xmlSW, XmlWriteMode.WriteSchema);...
10
by: Bilal | last post by:
Hello, I'm trying to perform some string manipulations in my stylesheet and have gotten stuck on the issue below so hopefully can elicit some useful hints. Namely, the problem is that I need to...
4
by: th1421 | last post by:
Hi, I'm new to FireFox. I am currently trying to convert my website to be compatible with it. Doing so I’m trying to process some XML/XSLT pages (preferably without using JavaScript). When I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.