Java Reference
In-Depth Information
DetailPageTransformBean.applyTransform(DetailPageXMLBean.getVehicleData
()))%>
The JavaBean required to apply the XSL transform is shown in Listing 15-11 . For ease of checkout, a
main method is included.
Caution
The only deployment problem you are likely to encounter is that the path for the
stylesheet defaults to Tomcat's/bin directory unless you specify the path fully.
Listing 15-11: XSL transform bean
package JavaDatabaseBible.ch15;
import java.io.*;
import org.xml.sax.SAXException;
import org.apache.xalan.xslt.XSLTProcessorFactory;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessor;
public class DetailPageTransformBean{
private String xslFileName = null;
private byte[] xmlSource = null;
private ByteArrayInputStream xmlInputStream = null;
public DetailPageTransformBean(){
}
public void setXmlSource(byte[] xmlSource){
this.xmlSource=xmlSource;
xmlInputStream = new ByteArrayInputStream(xmlSource);
}
public void setXslFileName(String xslFileName){
this.xslFileName=xslFileName;
File f = new File(xslFileName);
if(!f.exists())System.out.println("Cannot find file: "+xslFileName);
}
public byte[] applyTransform(byte[] xmlSource){
setXmlSource(xmlSource);
return applyTransform();
}
public byte[] applyTransform(){
Search WWH ::




Custom Search