You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Christopher Benson <be...@mindspring.com> on 2000/12/21 05:47:34 UTC

Beginner needs a little help, please...

I'm a brand new Java programmer so please forgive my ignorance.  Today I began to write my very first non-textbook-based Java program ever.  I'm attempting to use Xalan 2 and TRAX.
 
More specifically, I'm trying to create a javabean that can be called from a JSP and that will take an XML document and an XSLT document, do the transformation, and put the resulting code (HTML in this case) in a string.  The string could then be used to populate the JSP page through a GetProperty approach.  I think I'm on the right path, but I can't figure out how to get the result into the string.  When I attempt to compile, I get various errors depending on what I'm currently trying, but ultimately they all point to the fact that I'm doing the wrong things to populate the string with my result.  It seems to be the last section of the last line in the Transform() method that I'm having trouble with.
 
If anyone can provide some quick direction, I would be most grateful.  I've gone through the examples and gleaned everything I could from them.
 
Thank you very much,
Christopher Benson
benson@mindspring.com
__________________
 
package intellinet;
 
import org.apache.trax.Processor;
import org.apache.trax.Templates;
import org.apache.trax.Transformer;
import org.apache.trax.Result;
import org.apache.trax.ProcessorException;
import org.apache.trax.ProcessorFactoryException;
import org.apache.trax.TransformException;
 
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
 
import java.io.*;
 
public class IntelliTransform {
 
  private String xmlsource = null;
  private String xsltsource = null;
  private String result = null;
 
  public void Transform()
    throws ProcessorException, ProcessorFactoryException,
          TransformException, SAXException, IOException
  {
    Processor processor = Processor.newInstance("xslt");
    Templates templates = processor.process(new InputSource(xsltsource));
    Transformer transformer = templates.newTransformer();
    // I've left the extra line in to show some of my failed thinking...
    //transformer.transform(new InputSource(xmlsource), new Result(new StringWriter(result)));
    transformer.transform(new InputSource(xmlsource), new Result(new OutputStreamWriter(result)));
  }
 
  public void setXMLdoc(String xmldoc) {
    xmlsource = xmldoc;
  }
 
  public void setXSLTdoc(String xsltdoc) {
    xsltsource = xsltdoc;
  }
 
  public String getHTMLresult() {
    return result;
  }
 
}