javalogo

Transform XML into HTML using XSLT


Reference : http://www.rgagnon.com/javadetails/java-0407.html

How to transfrom XML into HTML using XSLT in Java?

public String view() throws SQLException{

//get XML from database before do print

System.out.println(xmlData);  //This is the result when I take the XML from database using hibernate framework.

try {

File file = new File(“xmlFile.xml”);

FileWriter fileWriter = new FileWriter(file);

fileWriter.write(xmlData);

fileWriter.flush();

fileWriter.close();

TransformerFactory tFactory = TransformerFactory.newInstance();

//We will transform xml into HTML using XSLT and save HTML file in local disk D

Transformer transformer = tFactory.newTransformer (

new javax.xml.transform.stream.StreamSource(“copy Path form1.XSL to here”));

transformer.transform( new javax.xml.transform.stream.StreamSource(file),  new

javax.xml.transform.stream.StreamResult ( new FileOutputStream(“D:/formWithData.html”)));

}

catch (Exception e) {

e.printStackTrace( );

}

}

 

One thought on “Transform XML into HTML using XSLT

  1. I’ve been surfing on-line greater than three hours nowadays, but I never found any interesting article like yours.
    It’s pretty price sufficient for me. In my opinion, if all webmasters and bloggers made
    excellent content as you did, the internet can be much more helpful than ever before. http://www.yahoo.net

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s