You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by borg borg <bo...@hotmail.com> on 2001/03/03 00:27:46 UTC
XSLT transformation Question?
I just recently moved to Xalan Java 2 and found my xslt transformation
stopped working.
What i'm trying to do is the following:
1. Take a xml string ( not a file )
2. Table a xslt file path
3. Convert it into a html file which I use to return.
Here is my original code under Xalan Java 1:
import java.io.StringWriter;
import java.io.PrintWriter;
import java.io.StringReader;
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 XSLTransformation
{
XSLTProcessor _Processor = null;
XSLTResultTarget _Target = null;
StringWriter _SWriter = null;
PrintWriter _PWriter = null;
public XSLTransformation()
{
}
public String Transformation( String strXML, String strXSLFile )
{
try
{
_SWriter = new StringWriter();
_PWriter = new PrintWriter( _SWriter, false );
_Processor = XSLTProcessorFactory.getProcessor();
StringReader _SReader = new StringReader( strXML );
_Processor.process( new XSLTInputSource( _SReader ),
new XSLTInputSource( strXSLFile ),
new XSLTResultTarget( _PWriter ));
return _SWriter.toString();
}
catch( Exception err )
{
System.err.println( err );
err.printStackTrace();
return null;
}
}
}
Which worked good. Now with Xalan Java 2 I noticed that some of the classes
are gone and been replaced with Trax
Here is my implementation. Just wondering if this seems correct.
Thanks
import java.io.StringWriter;
import java.io.PrintWriter;
import java.io.StringReader;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
public class XalanXSLT
{
StringWriter _SWriter = null;
PrintWriter _PWriter = null;
public XalanXSLT()
{
}
public String Transformation( String strXML, String strXSLFile )
{
try
{
_SWriter = new StringWriter();
_PWriter = new PrintWriter( _SWriter, false );
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer( new
StreamSource(strXSLFile));
StringReader _SReader = new StringReader( strXML );
transformer.transform( new StreamSource(_SReader),
new StreamResult( _SWriter ));
return _SWriter.toString();
}
catch( Exception err )
{
System.err.println( err );
err.printStackTrace();
return null;
}
}
}
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
Problem with running a xalan extension example
Posted by Vanessa D Johnson <va...@jpl.nasa.gov>.
I am having an issue trying to run the 3-java-namespace example with the
extensions - I get the following error:
XSLT Error (javax.xml.transform.TransformerException): IntDate
Also, I haven't seen an indication towards any reference to these in
classes in a classpath or similar environment variable. How does this work
exactly?
Thanks,
Vanessa
Vanessa D. Johnson
Advanced Mission Software Technology Group
Mission Execution and Automation - Section 368
Jet Propulsion Laboratory
voice: (818) 354-3885