This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes java program for xml and xsl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java program for xml and xsl" Watch "java program for xml and xsl" New topic
Author

java program for xml and xsl

raj kothari
Greenhorn

Joined: Nov 21, 2005
Posts: 24
I have an java code which does xml + xsl transform and gives me .html files. This works fine in win xp, however it doesnt work in linux. When running this, in linux, only empty html files are getting created. for information, I have data in xml, style defined in xsl and this code block is small part of full code where i feel is the issue. Please help.

FileOutputStream fos = new FileOutputStream(helpHtmlDir+ helpTreeHtmlFileName + "_" + productId + ".html");

OutputStreamWriter osw = new OutputStreamWriter(fos,Utf8Charset);

BufferedWriter br = new BufferedWriter(osw);

InputStream xmlIs = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFileName);

StreamSource xmlSource = new StreamSource(xmlIs);

if (xmlSource != null) {
StringWriter sw = new StringWriter();
StreamResult sr = new StreamResult(sw);
Map params = new HashMap(2);
XSLTransformUtil.doTransform(xmlSource, helpTreeXslFile,sr, params);
br.write(sw.toString());
}

br.close();
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Your code doesn't do a lot of error checking. What happens if xmlSource == null? Are you sure that the filename you're using is correct, so that getResourceAsStream() can find it?

Add some error checking code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java program for xml and xsl
 
Similar Threads
Apply XSL to XML (Java)
Passing HTML string/stream to Browser
Servlet XML Transformation problem
unable to remove spaces in xml
DocumentBuilder.parse not working for String input