Hi All,
I am facing the problem while compiling xsl file using Translets.
When I compile it using Transformers I haven't faced any problem. But
I don't know why I am facing the problem using Translets. I tried to
find the solution for this problem on google. But most of the guys
are getting the same problem, but it seems they doesn't get the
solution for this.
I included both the developers and users group because, I am expecting
a postive revert from the developers as they know the root cause for
this exception
I am also includong Source code for which I am getting exceptions
import java.io.* ;
import javax.xml.transform.* ;
import javax.xml.transform.stream.* ;
public class XSLCompiler
{
public static void main ( String[] args )
throws Exception
{
XSLCompiler app = new XSLCompiler () ;
app.transform ( "c:/eml.xsl") ;
}
/**
* Compiles an XSL stylesheet into a translet, wraps tshe translet
* inside a Templates object and dumps it to a file.
*/
public Transformer getTransformer ( String xsl ) throws Exception
{
try
{
// Set XSLTC's TransformerFactory implementation as the default
System.setProperty ( "javax.xml.transform.TransformerFactory" ,
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl"
) ;
// Get an input stream for the XSL stylesheet
StreamSource stylesheet = new StreamSource ( xsl ) ;
// The TransformerFactory will compile the stylesheet and
// put the translet classes inside the Templates object
TransformerFactory factory = TransformerFactory.newInstance () ;
factory.setAttribute ( "generate-translet" , Boolean.TRUE ) ;
Templates templates = factory.newTemplates ( stylesheet ) ;
Transformer transformer = templates.newTransformer () ;
return transformer ;
}
catch ( Exception e )
{
System.err.println ( "Exception: " + e ) ;
e.printStackTrace () ;
throw new Exception("Error ",e);
}
}
public void transform ( String xslFileName )
throws Exception
{
Transformer transformer = getTransformer ( xslFileName ) ;
if ( transformer == null )
{
throw new RuntimeException ( "Bad XSL File or transformer
creation problem" ) ;
}
ByteArrayOutputStream transformmedStream = new
ByteArrayOutputStream () ;
FileInputStream fin = new FileInputStream ( "c:/111.xml" ) ;
transformer.transform ( new StreamSource ( fin ) , new
StreamResult ( transformmedStream ) ) ;
System.err.println(transformmedStream.toString());
}
private void usage ()
{
System.err.println ( "Usage: XSLCompiler <xsl_file>" ) ;
System.exit ( 1 ) ;
}
}
Thanks
Sudhakar
ERROR: 'org.apache.xml.utils.XMLChar.isValidQName(Ljava/lang/String;)Z'
FATAL ERROR: 'Could not compile stylesheet'
Exception: javax.xml.transform.TransformerConfigurationException:
Could not compile stylesheet
javax.xml.transform.TransformerConfigurationException: Could not
compile stylesheet
at
org.apache.xalan.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:753)
at XSLCompiler.getTransformer(XSLCompiler.java:47)
at XSLCompiler.transform(XSLCompiler.java:63)
at XSLCompiler.main(XSLCompiler.java:25)
java.lang.Exception: Error
at XSLCompiler.getTransformer(XSLCompiler.java:55)
at XSLCompiler.transform(XSLCompiler.java:63)
at XSLCompiler.main(XSLCompiler.java:25)
Caused by: javax.xml.transform.TransformerConfigurationException:
Could not compile stylesheet
at
org.apache.xalan.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:753)
at XSLCompiler.getTransformer(XSLCompiler.java:47)
... 2 more
Exception in thread "main"
import java.io.* ;
import javax.xml.transform.* ;
import javax.xml.transform.stream.* ;
public class XSLCompiler
{
public static void main ( String[] args )
throws Exception
{
XSLCompiler app = new XSLCompiler () ;
app.transform ( "c:/eml.xsl") ;
}
/**
* Compiles an XSL stylesheet into a translet, wraps tshe translet
* inside a Templates object and dumps it to a file.
*/
public Transformer getTransformer ( String xsl ) throws Exception
{
try
{
// Set XSLTC's TransformerFactory implementation as the default
System.setProperty ( "javax.xml.transform.TransformerFactory" ,
"org.apache.xalan.xsltc.trax.TransformerFactoryImpl" ) ;
// Get an input stream for the XSL stylesheet
StreamSource stylesheet = new StreamSource ( xsl ) ;
// The TransformerFactory will compile the stylesheet and
// put the translet classes inside the Templates object
TransformerFactory factory = TransformerFactory.newInstance () ;
factory.setAttribute ( "generate-translet" , Boolean.TRUE ) ;
Templates templates = factory.newTemplates ( stylesheet ) ;
Transformer transformer = templates.newTransformer () ;
return transformer ;
}
catch ( Exception e )
{
System.err.println ( "Exception: " + e ) ;
e.printStackTrace () ;
throw new Exception("Error ",e);
}
}
public void transform ( String xslFileName )
throws Exception
{
Transformer transformer = getTransformer ( xslFileName ) ;
if ( transformer == null )
{
throw new RuntimeException ( "Bad XSL File or transformer creation problem" ) ;
}
ByteArrayOutputStream transformmedStream = new ByteArrayOutputStream () ;
FileInputStream fin = new FileInputStream ( "c:/111.xml" ) ;
transformer.transform ( new StreamSource ( fin ) , new StreamResult ( transformmedStream ) ) ;
System.err.println(transformmedStream.toString());
}
private void usage ()
{
System.err.println ( "Usage: XSLCompiler <xsl_file>" ) ;
System.exit ( 1 ) ;
}
}