2013-10-11 28 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。