我正在简单代理服务中对传入的Soap/http请求执行XSLT转换。我收到以下错误。
注意:我使用的是WSO2 ESB 4.8.1。
错误:
Unable to perform XSLT transformation using : Value {name ='null', keyValue ='gov:/xslt/Interface.xslt'} against source XPath : s11:Body/child::*[position()=1] | s12:Body/child::*[position()=1] reason : Unable to create an OMElement using XSLT result {org.apache.synapse.mediators.transform.XSLTMediator}
org.apache.synapse.SynapseException: Unable to create an OMElement using XSLT result
at org.apache.synapse.mediators.transform.XSLTMediator.performXSLT(XSLTMediator.java:302)
at org.apache.synapse.mediators.transform.XSLTMediator.mediate(XSLTMediator.java:191)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:166)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:411)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:183)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[4,16]
Message: Content is not allowed in prolog.
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
at org.apache.axiom.om.impl.llom.OMDocumentImpl.getOMDocumentElement(OMDocumentImpl.java:109)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:570)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:566)
at org.apache.synapse.util.jaxp.StreamResultBuilder.getNode(StreamResultBuilder.java:87)
at org.apache.synapse.mediators.transform.XSLTMediator.performXSLT(XSLTMediator.java:300)
... 12 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[4,16]
Message: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:598)
at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
at org.apache.axiom.util.stax.dialect.SJSXPStreamReaderWrapper.next(SJSXPStreamReaderWrapper.java:138)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)
... 17 more
XSLT文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:con="http://com.example/cdm/contract/v1" xmlns:lic="http://com.example/cdm/license/v1" xmlns:org="http://com.example/cdm/organization/v1" xmlns:tns="http://com.example/cdm/order/v1" xmlns:tns1="http://com.example/cdm/customer/v1" xmlns:tns3="http://com.example/cdm/address/v1" xmlns:tns4="http://com.example/cdm/person/v1" xmlns:tns5="http://com.example/cdm/productoffer/v1" xmlns:tns6="http://com.example/cdm/product/v1" xmlns:tns7="http://com.example/cdm/productofferprice/v1" exclude-result-prefixes="tns tns1 tns4 tns3 tns5 tns6 tns7" version="1.0">
<xsl:template match="/tns:OrderRequest">
<tns:OrderRequest>
<tns:Order>
<tns:OrderHeader>
<tns:OrderNumber>
<xsl:value-of select="tns:OrderHeader/tns:OrderNumber" />
</tns:OrderNumber>
</tns:OrderHeader>
</tns:Order>
</tns:OrderRequest>
</xsl:template>
</xsl:stylesheet>
问题:我不知道我的XSLT文件出了什么问题。我在序言中什么也没看到。
该错误表示转换的结果在根元素之前有非空白文本。对此的唯一解释是,您的模板从未被触发,并且只应用默认模板(复制文本节点,但不复制元素)。这意味着变换的输入的根元素不是tns:OrderRequest
。
看起来您的配置和请求负载与此错误有关。请提供您的代理服务配置和输入xml负载,以便您了解更多信息。
如果您在Error中得到"Unable to create an OMElement using XSLT result",则表示您的模板/命名空间在XSLT中与请求消息不匹配。请在此处查看开发人员的评论
此错误通常预期的Payload不是XSLT处理的。一旦你得到这个错误,在所有传入的有效载荷都失败后,处理它是否是正确的有效载荷。
解决方案:更改本地项和代理服务文件中的键值后,重新启动wso2esb。
永久解决方案:编写自定义XSLT中介来解决此问题