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();
}
}
}
闽公网安备 35060202000074号