2013-10-11 65 views
0

我有這個樣式表撒克遜transfromation

<xsl:stylesheet version="1.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
       xmlns:tes="http://testwork/"> 
    <xsl:template match="/"> 
     <xsl:apply-templates select="soapenv:Envelope/soapenv:Body/*"/> 
    </xsl:template> 
    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

與此XML文件

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testwork/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <tes:sayHelloWorldFrom> 
     <!--Optional:--> 
     <arg0>?</arg0> 
     </tes:sayHelloWorldFrom> 
    </soapenv:Body> 
</soapenv:Envelope> 

我想從這個XML與此XSL得到一個身體,我使用撒克遜進行了改造,在這裏它是我的一段代碼

public void get(String xml, String xsl) throws ServiceException { 
TransformerFactory tFactory = TransformerFactory.newInstance(); 
Transformer transformer = tFactory.newTransformer(new StreamSource(xsl));   
transformer.transform(new StreamSource(xml), new StreamResult(System.out)); 

但該方法的執行過程中我有一個錯誤

javax.xml.transform.TransformerConfigurationException:無法通過 編譯樣式表。檢測到1個錯誤。 在net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:220) 在net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:132) 在net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl。 java:87) at service.ResponseService.getRequestSoapBody(ResponseService.java:76)

那麼,怎麼了?提前Thanx

+1

我測試了你的代碼,從命令行運行Saxon 9.5 HE,並且它沒有提供錯誤。你使用哪個版本?你的代碼中唯一奇怪的事情是XSLT 2.0處理器的'version =「1.0」',但它只能給出警告,而不是錯誤。 –

回答

1

錯誤的第一件事是您沒有顯示編譯器錯誤消息。 Saxon默認將消息發送到System.err,但是如果您位於具有圖形用戶界面的應用程序中,那麼您很可能無法看到寫入的內容。所以將消息重定向到別的地方。您可以使用System.setErr()將其引導至文件或GUI應用程序中的窗口;在撒克遜一級還有一些控件將不同編輯的輸出發送到不同的目的地。

您向我們展示的代碼沒有任何問題。

我懷疑(但這只是一個猜測)你的變量「xsl」包含樣式表代碼作爲字符串,而它應該包含樣式表位置的URI。