xsl - transform
Сервлет ничего не выводит
PrintWriter out = response.getWriter();
InputStream xslStream =
getServletContext().getResourceAsStream("/book.xsl");
try {
Source xmlSource = new DOMSource( document );
Source xslSource = new StreamSource(xslStream);
StreamResult result = new StreamResult(output);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer( xslSource );
transformer.transform(xmlSource, result);
} catch (TransformerException transformerException) {
transformerException.printStackTrace(System.err);
}
--------------------------------------
Код:
PrintWriter out = response.getWriter();
Не увидел, где в коде out используется. Потому, наверно, ничего и не выводится.
StreamResult result = new StreamResult(out);
.........................
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
InputStream xslStream = getServletContext().getResourceAsStream("/book.xsl");
transform(Document, xslStream, out);
.........................
.........................
private void transform( Document document, InputStream xslStream, PrintWriter output) {
try {
Source xmlSource = new DOMSource(document);
Source xslSource = new StreamSource(xslStream);
StreamResult result = new StreamResult(output);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer( xslSource );
transformer.transform(xmlSource, result);
} catch (TransformerException transformerException) {
transformerException.printStackTrace(System.err);
}
}
1) ByteArrayOutputStream out = new ByteArrayOutputStream();
2) посмотри до пропертей transformer'a - transformet.setOutputProperty(OutputKeys.<property>, <value>);
(например, я всегда явно задаю пропертя OutputKeys.ENCODING)
И после етого продебагай свой код и посмотри что идет в out. Мне било-би так удобней.