java 使用xml和xsl格式字符串转换html字符串
java 使用xml和xsl格式字符串转换html字符串
public static String TransformXmlToHtml(String xml, String xsl) {
try {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xsl.getBytes("GBK"));
InputStream xslInputStream = byteArrayInputStream;
ByteArrayInputStream byteArrayInputStream2 = new ByteArrayInputStream(xml.getBytes("GBK"));
InputStream xmlInputStream = byteArrayInputStream2;
Source xslSource = new StreamSource(xslInputStream);
Source source = new StreamSource(xmlInputStream);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Result result = new StreamResult(bytes);
TransformerFactory tFac = TransformerFactory.newInstance();
Transformer t = tFac.newTransformer(xslSource);
t.setOutputProperty(OutputKeys.ENCODING,"GBK");
t.transform(source, result);
return bytes.toString("GBK");
} catch (Exception e) {
e.printStackTrace();
}
return "";
}