Java核心代码例程之:(JAXP) XSL Transformation

王朝java/jsp·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

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 includes these JARs) here: http://java.sun.com/xml/

* Find additional Xerces and Xalan info here: http://xml.apache.org/

*

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

* You"ll find good XSL info here: http://www.w3.org/Style/XSL/#learning

**/

public class TransformDemo

{

public static void main( String[] args )

{

try

{

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 ) );

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航