public String styleDocument(Document document, String stylesheet) throws Exception {
// load the transformer using JAXP
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource( stylesheet ));
// now lets style the given document
DocumentSource source = new DocumentSource( document );
DocumentResult result = new DocumentResult();
transformer.transform( source, result );
// return the transformed document
Document transformedDoc = result.getDocument();
return transformedDoc.asXML();
}
使用上面的方法出现错误
错误:“no protocol: <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <h1> <xsl:value-of select="//title"/> </h1> <h2> <xsl:value-of select="//author"/> </h2> </xsl:template></xsl:stylesheet>”
致命错误:“无法编译样式表”
请高手指教!!!
// load the transformer using JAXP
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource( stylesheet ));
// now lets style the given document
DocumentSource source = new DocumentSource( document );
DocumentResult result = new DocumentResult();
transformer.transform( source, result );
// return the transformed document
Document transformedDoc = result.getDocument();
return transformedDoc.asXML();
}
使用上面的方法出现错误
错误:“no protocol: <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <h1> <xsl:value-of select="//title"/> </h1> <h2> <xsl:value-of select="//author"/> </h2> </xsl:template></xsl:stylesheet>”
致命错误:“无法编译样式表”
请高手指教!!!