WSO2中无法执行XSLT转换问题求助
问题:XSLT转换时报"The evaluation of the XPath expression xslt-data did not result in an OMNode : null"错误
错误详情
The evaluation of the XPath expression xslt-data did not result in an OMNode : null org.apache.synapse.SynapseException: The evaluation of the XPath expression xslt-data did not result in an OMNode : null
场景说明
自定义Class Mediator调用后端端点,将返回的JSONArray转换为XML字符串后存入上下文属性;通过Payload Factory mediator格式化XML负载后传给XSLT Mediator时触发上述错误,但使用Respond Mediator能正常返回正确的XML数据。
Class Mediator生成的XML内容
<array> <discount>0.0000</discount> <locale>en</locale> <total_tax>10.8900</total_tax> <customer_id>315</customer_id> <currency_id>UN</currency_id> </array> <array> <discount>1.23</discount> <locale>un</locale> <total_tax>10.45</total_tax> <customer_id>316</customer_id> <currency_id>USD</currency_id> </array>
当前Payload Factory配置
<payloadFactory media-type="xml"> <format> <data xmlns=""> $1 </data> </format> <args> <arg evaluator="xml" expression="get-property('RESPONSE')"/> </args> </payloadFactory> <property name="messageType" scope="axis2" type="STRING" value="application/xml"/>
解决方案
问题根源
存入RESPONSE属性的是无根节点的XML字符串,使用evaluator="xml"解析时,因XML结构不合法(多个同级根节点)无法生成有效的OMNode对象,导致XSLT Mediator无法找到可处理的节点。
修复步骤
优先修改Class Mediator:
转换JSONArray时直接给XML添加根节点,例如外层包裹<root>标签,确保生成的XML是合法的单根结构,再存入上下文属性。调整Payload Factory配置(无需修改Class Mediator):
将参数的evaluator改为text,直接将XML字符串作为文本插入,让Payload Factory自动构建合法的单根XML:<payloadFactory media-type="xml"> <format> <data xmlns=""> $1 </data> </format> <args> <arg evaluator="text" expression="get-property('RESPONSE')"/> </args> </payloadFactory> <property name="messageType" scope="axis2" type="STRING" value="application/xml"/>检查XSLT Mediator配置:
确保XSLT Mediator的source指向当前消息体(如$body),而非无效的属性,示例:<xslt key="your-xslt-template-key" source="$body"/>
内容的提问来源于stack exchange,提问作者Ruby
相关产品推荐
相关产品推荐

