1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
try {
InputStream inputStream;
//chargement du xsl
File stylesheet = new File("stylesheet.xsl");
//String xslt = "";
//inputStream = new ByteArrayInputStream(xslt);
StreamSource stylesource = new StreamSource(stylesheet);
//instantiation du transformer
Templates template = fabrique.newTemplates(stylesource);
Transformer transformer;
transformer = template.newTransformer();
//configuration du transformer
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
//création du XML source
String doc = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+this._content;
inputStream = new ByteArrayInputStream(doc.getBytes());
InputSource inputSource = new InputSource(inputStream);
SAXSource source = new SAXSource(inputSource);
//création de l'objet de sortie
//ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
StreamResult resultat = new StreamResult();
//transformation
transformer.transform(source,resultat);
//conversion de l'objet de resultat sous forme de chaine
ByteArrayOutputStream outputStream = (ByteArrayOutputStream)resultat.getOutputStream();//cette ligne est-elle nécessaire?
this._content=outputStream.toString();
} catch (TransformerConfigurationException ex) {
ex.printStackTrace();
} |
Partager