Dear all,
        I am writing 2 classes to do a simple transfrom  of XML+XSL
using XALAN.The first one take the xml string and the XSL file name from
user, and then pass these infomation to the second class to convert it.The
second class is copied from your sample SimpleTransform.java. It works
prefectly in command-line mode. 
        The problem is when I try to change the
first class to a JSP page, and I copy the structure to the JSP. The
SimpleTransform keep throw the TransformerConfigurationException with the
message "Namespace not supported by SAXParser". After I inspect my coding,
I am sure all the classpath is correct and the path to xsl is also
correct. And the exception is orginated form the statement "Transformer
transformer = tFactory.newTransformer(new StreamSource(xsl));". Would you
kindly help me to locate the problem? Attachment is the problem converting
class.

Best Regards,
Patrick

// Imported TraX classes

import javax.xml.transform.*;

import javax.xml.transform.stream.*;



// Imported java classes

import java.io.*;



public class XML_XSL_Transform

{

  public static String Transform(String xsl,String xml)

  {  

        StringWriter out = new StringWriter();

        try{

                // Use the static TransformerFactory.newInstance() method to 
instantiate 

                // a TransformerFactory. The javax.xml.transform.TransformerFactory 

                // system property setting determines the actual class to instantiate 
--

                // org.apache.xalan.transformer.TransformerImpl.

                TransformerFactory tFactory = TransformerFactory.newInstance();

        

                // Use the TransformerFactory to instantiate a Transformer that will 
work with  

                // the stylesheet you specify. This method call also processes the 
stylesheet

                // into a compiled Templates object;

                Transformer transformer = tFactory.newTransformer(new 
StreamSource(xsl));



                // Use the Transformer to apply the associated Templates object to an 
XML document

                // (foo.xml) and write the output to a file (foo.out).

                transformer.transform(new StreamSource(new StringReader(xml)), new 
StreamResult(out));

                }catch(Exception e){

                        System.err.println("Transform: "+e.getMessage());

                        e.printStackTrace(new PrintWriter(out));

                }

                return out.toString();

        }

}

Reply via email to