The project needs to be converted to HTML file storage using Xml+xsl.
I've never done anything like this before, the results of Internet search basically XML and XSL are saved and typed as files, but I've got the string here, so consider whether you can use the string directly.
It is perfectly feasible to read the code found for the corresponding streamsource.
In addition, most of the examples on the web may appear filenotfoundexception anomalies, fortunately found a solution.
Here is the code:
/** * Convert to HTML file using xml+xsl * @param XML XML content String * @param xsl xsl content string * @param htmlfilepath Destination HTML file path */private void trans Formbyxslt (String xml,string xsl,string htmlfilepath) {transformerfactory transformerfactory = Transformerfactory.newinstance (); StringReader xslreader = new StringReader (XSL); Streamsource Xslsource = new Streamsource (xslreader); try {Transformer Transformer = Transformerfactory.newtransformer ( Xslsource);//Set the output file character set Transformer.setoutputproperty ("Encoding", "UTF-8"); StringReader xmlReader = new StringReader (XML); Streamsource Xmlsource = new Streamsource (XmlReader); File Htmlfile = new file (Htmlfilepath), or//If you do not use Htmlfile.touri (). GetPath (), filenotfoundexceptionresult result may appear New Streamresult (Htmlfile.touri (). GetPath ()); Transformer.transform (xmlsource, result);} catch (Transformerconfigurationexception e) {e.printstacktrace ();} catch (Transformerexception e) {e.printstacktrace ( );}}
Htmlfile.touri (). GetPath ()) This can avoid filenotfoundexception exceptions, thanks to http://blog.csdn.net/yangxiaonawzy/article/ details/5806413 this article.
Xml+xsl Convert to HTML