Java core code: XSL Transformation

Source: Internet
Author: User
Tags xsl xsl file xslt

Import javax. xml. transform .*;

Import javax. xml. transform. stream .*;


* TransformDemo uses JAXP to acquire an XML Transformer. It uses the Transformer

* To transform an XML shopping cart into an HTML view of the shopping cart.

* The Transformer uses transform instructions in an XSLT (. xsl) file.


* The following JARs must be in your CLASSPATH:

*-Jaxp. jar

*-Xerces. jar (for SAX parser and DOM object implementations)

*-Xalan. jar (for XSLT implementation)


* Download JAXP (which has des these JARs) here:

* Find additional Xerces and Xalan info here:


* Note: XSLT authoring/programming is beyond the scope of this tutorial.

* You "ll find good XSL info here:


Public class TransformDemo


Public static void main (String [] args)




TransformerFactory factory = TransformerFactory. newInstance ();

System. out. println ("TransformerFactory classname:" + factory. getClass (). getName ());

Transformer transformer = factory. newTransformer (new StreamSource ("cart. xsl "));

System. out. println ("Transformer classname:" + transformer. getClass (). getName ());

// This single line applies the XSL file to transform the XML into HTML.

Transformer. transform (new StreamSource ("cart. xml"), new StreamResult (System. out ));


Catch (Exception e)


E. printStackTrace ();




Related Article

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: 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.