tags:

views:

196

answers:

1

Hi
i'm getting exception on Transformer transformer = tFactory.newTransformer(StreamXSL); but the error below is not explicit i cannot understand why "Could not compile stylesheet" ?

Tks

static String getHtml(String xml)
{
    Element elementObj = getElementObject(xml);
    String xslName = getValueOfElement(elementObj, xml, "XSL_TO_RUN");
    StreamSource StreamXML = new StreamSource(new StringReader(xml));
    try{
        TransformerFactory tFactory = TransformerFactory.newInstance();

        if(xslName!=null){

            String xslfile  = xslName;

            File xfile = new File(xslfile);
            if (xfile.exists()){}
            else
            {
                 LogI.log(4,"getHtml:: ERROR:  xsl file don´t Exist! " + xslName );
                 return null;
            }
            StreamSource StreamXSL = new StreamSource(xfile);

            Transformer transformer = tFactory.newTransformer(StreamXSL);



        }else{
            LogI.log(0,"getHtml::ERROR->Error on create  stream XSL");
            return null;
        }

    }   catch(TransformerConfigurationException ex){
        LogI.log(0,"getHtml::Erro crossing the XML with the XSL:" + ex);
        LogI.log(0,"getHtml::Erro crossing the XML with the XSL(1):" + ex.getMessageAndLocation());
        LogI.log(0,"getHtml::Erro crossing the XML with the XSL(2):" + ex.getMessage());
        for(int i=0;i<ex.getStackTrace().length;i++){
            LogI.log(0, "ARQ::Pedido:: ERRO(2) ->" + ex.getStackTrace()[i]);
        }

        return null;

    } catch(Exception e){
        LogI.log(0,"getHtml::Erro crossing the XML with the XSL:" + e);
        //out.clear();
        //out.println(errorPage);
        return null;
    }
}

Here is the output:

ERRO: getHtml::Erro crossing the XML with the XSL:javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
ERRO: getHtml::Erro crossing the XML with the XSL(1):Could not compile stylesheet
ERRO: getHtml::Erro crossing the XML with the XSL(2):Could not compile stylesheet
ERRO: ARQ::Pedido:: ERRO(2) ->com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(Unknown Source)
ERRO: ARQ::Pedido:: ERRO(2) ->com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(Unknown Source)
ERRO: ARQ::Pedido:: ERRO(2) ->BizBanc.Arq.getHtml(Arq.java:189)
ERRO: ARQ::Pedido:: ERRO(2) ->BizBanc.Arq.getResponse(Arq.java:792)
A: 

Your output shows that you're getting a TransformerConfigurationException; according to [the API](http://java.sun.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newTransformer(javax.xml.transform.Source)), those are

"Thrown if there are errors when parsing the Source or it is not possible to create a Transformer instance."

Your syntax seems okay, so I suspect that your file is causing the problem. I see that you're checking to make sure the file exists, but are you sure its contents are okay?

Lord Torgamus
xsl is ok as is used in a tomcat environment without erros...
Reversed
You were right my xsl had duplicated fields! Thanks for you help!
Reversed