2010-03-15 77 views
0

我在Transformer transformer = tFactory.newTransformer(StreamXSL); 上收到異常,但下面的錯誤不是顯式的,我不明白爲什麼「無法編譯樣式表」?Java:XML/XSL Transformer如何獲取有關錯誤的更多信息?

韓國社交協會

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; 
    } 
} 

這裏是輸出:

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) 

回答

0

你的輸出顯示你得到一個TransformerConfigurationException;根據[該API](http://java.sun.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newTransformer(javax.xml.transform.Source)),這些都是

「時拋出,如果有解析來源時,錯誤或者無法創建Transformer實例。」

你的語法看起來沒問題,所以我懷疑你的文件是造成這個問題,我看到你正在檢查,以確保文件存在,但你確定它的內容是好嗎?

+0

xsl是好的,因爲在沒有錯誤的tomcat環境中使用。 .. – Reversed 2010-03-15 16:48:21

+0

你是對的我的xsl有重複的字段! 感謝您的幫助! – Reversed 2010-03-18 18:19:46

相關問題