Xml+xsl Convert to HTML

Source: Internet
Author: User
Tags xsl

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.