| |
技术文档>>JAVA>>新手入门>>基础入门>查看文档 |
|
| |
java核心代码例程之:(jaxp) xsl transformation |
|
| |
文章作者:未知 文章来源:水木森林 |
|
| |
查看:216次 录入:管理员--2007-11-17 |
|
| |
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 ) ); } catch( exception e ) { e.printstacktrace(); }
}
}
|
|