XML transformation : XML Transform « JSP « Java Tutorial






<%@ page import="javax.xml.transform.*, javax.xml.transform.stream.*, java.io.*" %>

<% 
    try 
    {  
        TransformerFactory transformerfactory = TransformerFactory.newInstance(); 
        Transformer transformer = transformerfactory.newTransformer(new StreamSource(new File    
            (application.getRealPath("/") + "your.xsl")));

        transformer.transform(new StreamSource(new File(application.getRealPath("/") + "your.xml")), 
        new StreamResult(new File(application.getRealPath("/") + "your.html")));

    }
    catch(Exception e) {}  

    FileReader filereader = new FileReader(application.getRealPath("/") + "your.html");
    BufferedReader bufferedreader = new BufferedReader(filereader);
    String instring;

    while((instring = bufferedreader.readLine()) != null) { 
%>
        <%= instring %>
<%
        }
        filereader.close();
%>








23.55.XML Transform
23.55.1.JSTL XML Transform
23.55.2.XML transformation
23.55.3.Performing XSL Transformations