|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Feb 2003
Città: Formia
Messaggi: 1545
|
Jsp xml xsl
Qualcuno di voi ha mai fatto trasformazioni xml xsl utilittando jsp?
io le ho sempre fatte con toll oppure utilizzando cocoon.
__________________
Il portale delle infomazioni di Latina e Provincia Giralatina.it e’ nato con il preciso intento di promuovere varie attività che si svolgono nella provincia di Latina http://www.giralatina.it Il Blog dei Pendolari http://www.giralatina.it/blog/mybloggie/index.php |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Feb 2003
Città: Formia
Messaggi: 1545
|
Questo è un esempio ma manca ancora la gestione dei parametri per xsl
<%@ page import="javax.servlet.jsp.JspWriter, java.sql.*, java.util.*"%> <%@ page import="javax.xml.transform.*"%> <%@ page import="javax.xml.transform.stream.*"%> <%@ page import="java.io.*"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Documento senza titolo</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <% String path = "c:"; String xmlfile = path+"/prova.xml"; String xslfile = path+"/prova.xsl"; out.write("nome file xml "+xmlfile); out.write("<br>"); out.write("nome file xsl "+xslfile); out.write("<br>"); String testo = creaHtml(xmlfile,xslfile,path); out.write("Risultato. -->"); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(xslfile)); transformer.transform(new StreamSource(xmlfile), new StreamResult(out)); %> <% try{ // apre il file copywrite.txt in scrittura FileWriter fileout = new FileWriter(getServletContext().getRealPath("/")+"prova.html"); fileout.write(testo); fileout.close(); // chiude il file }catch (Exception e){ out.write("errore "); } %> </body> </html> <%! public String creaHtml(String fileXml,String xslFile,String percorsoXml) { StringWriter fileHtml = new StringWriter(); try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile)); transformer.setParameter("param1",percorsoXml); transformer.transform(new StreamSource(fileXml), new StreamResult(fileHtml)); } catch(Exception exc) { return "Errore:"+ exc.getMessage(); } return fileHtml.toString(); } %>
__________________
Il portale delle infomazioni di Latina e Provincia Giralatina.it e’ nato con il preciso intento di promuovere varie attività che si svolgono nella provincia di Latina http://www.giralatina.it Il Blog dei Pendolari http://www.giralatina.it/blog/mybloggie/index.php |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:38.



















