0% found this document useful (0 votes)
2 views

java XSLT

The document is a Java program that demonstrates how to use XSLT for transforming an XML file into an HTML file. It utilizes the TransformerFactory to load an XSLT stylesheet and an XML document, then applies the transformation and saves the output. The program also includes error handling to catch exceptions during the transformation process.

Uploaded by

prathikaanand
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

java XSLT

The document is a Java program that demonstrates how to use XSLT for transforming an XML file into an HTML file. It utilizes the TransformerFactory to load an XSLT stylesheet and an XML document, then applies the transformation and saves the output. The program also includes error handling to catch exceptions during the transformation process.

Uploaded by

prathikaanand
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import javax.xml.transform.

*;
import javax.xml.transform.stream.*;
import java.io.*;

public class XSLTExample {


public static void main(String[] args) {
try {
// Create a transformer factory
TransformerFactory factory = TransformerFactory.newInstance();

// Load the XSLT stylesheet


StreamSource xslt = new StreamSource(new File("books.xsl"));

// Create a transformer from the XSLT stylesheet


Transformer transformer = factory.newTransformer(xslt);

// Load the XML document


StreamSource xml = new StreamSource(new File("books.xml"));

// Define the output file (HTML)


StreamResult result = new StreamResult(new File("books.html"));

// Apply the transformation (XML -> XSLT -> HTML)


transformer.transform(xml, result);

System.out.println("Transformation complete. Output saved as


books.html");

} catch (Exception e) {
e.printStackTrace();
}
}
}

You might also like