我正在尝试使用 WSO2 ESB 模板中的 XSLT 重命名标签。
我所有的尝试都得到了同样的错误:无法使用 XSLT 结果创建 OMElement。
我尝试过的一种变体是:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:param name="response_tag"/>
<xsl:template match="RESPONSE">
<xsl:element name="{$response_tag}" >
<xsl:for-each select="/RESPONSE/*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
另一个是:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="request_tag"/>
<xsl:template match="RESPONSE">
<xsl:element name="{$request_tag}">
<xsl:apply-templates select="node() | @*" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我究竟做错了什么?
PS。参数response_tag
值与rns:NameOfResponse
命名空间 ( rns
)类似,NameOfResponse
每次都可能不同。命名空间位于 xml 的 Envelope 标记内,因此最终(如果转换有效),xml 将是有效的。
输入将类似于:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rns="http://www.example.com/example">
<soapenv:Header/>
<soapenv:Body>
<RESPONSE xmlns="http://ws.apache.org/ns/synapse">
<tag>123</tag>
<another_tag>20160622134457473</another_tag>
...
</RESPONSE>
</soapenv:Body>
</soapenv:Envelope>
结果应该是:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rns="http://www.example.com/example">
<soapenv:Header/>
<soapenv:Body>
<rns:NameOfResponse>
<tag>123</tag>
<another_tag>20160622134457473</another_tag>
...
</rns:NameOfResponse>
</soapenv:Body>
</soapenv:Envelope>
聚苯乙烯。尝试从响应标签中删除命名空间 - 即响应标签看起来像:NameOfTag
现在。同样的错误。