【发布时间】:2014-09-29 20:38:00
【问题描述】:
我是 XSLT / XPath 的新手 ....
我有以下 XML 消息...
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<request xmlns="http://ws.apache.org/ns/synapse">
<gam:process xmlns:gam="http://gamopera.ifpl.csi.it">
<!--Zero or more repetitions:-->
<gam:id>1</gam:id>
<gam:id>3</gam:id>
<gam:id>5</gam:id>
<gam:id>7</gam:id>
<gam:id>438</gam:id>
<gam:id>2</gam:id>
<gam:id>4</gam:id>
<gam:id>6</gam:id>
<gam:id>8</gam:id>
</gam:process>
<ax2586:good xmlns:ax2586="http://gamopera.ifpl.csi.it">
<ax2586:id>1</ax2586:id>
<ax2586:id>3</ax2586:id>
<ax2586:id>5</ax2586:id>
<ax2586:id>7</ax2586:id>
</ax2586:good>
</request>
</soapenv:Body>
</soapenv:Envelope>
我想得到这样的东西
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<ns:processResponse xmlns:ns="http://gamopera.ifpl.csi.it">
<ns:return xsi:type="ax2586:Result" xmlns:ax2586="http://dto.gamopera.ifpl.csi.it/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax2586:good xsi:type="ax2586:ElencoId" xmlns:ax2586="http://gamopera.ifpl.csi.it">
<ax2586:good>
<ax2586:id>1</ax2586:id>
<ax2586:id>3</ax2586:id>
<ax2586:id>5</ax2586:id>
<ax2586:id>7</ax2586:id>
</ax2586:good>
</ax2586:good>
<ax2586:message>Message Store does not exist.</ax2586:message>
<ax2586:statusCode>0</ax2586:statusCode>
<ax2586:wrong xsi:type="ax2586:ElencoId">
<ax2586:wrong xmlns:ax2586="http://gamopera.ifpl.csi.it">
<gam:id xmlns:gam="http://gamopera.ifpl.csi.it" xmlns="http://ws.apache.org/ns/synapse">438</gam:id>
<gam:id xmlns:gam="http://gamopera.ifpl.csi.it" xmlns="http://ws.apache.org/ns/synapse">2</gam:id>
<gam:id xmlns:gam="http://gamopera.ifpl.csi.it" xmlns="http://ws.apache.org/ns/synapse">4</gam:id>
<gam:id xmlns:gam="http://gamopera.ifpl.csi.it" xmlns="http://ws.apache.org/ns/synapse">6</gam:id>
<gam:id xmlns:gam="http://gamopera.ifpl.csi.it" xmlns="http://ws.apache.org/ns/synapse">8</gam:id>
</ax2586:wrong>
</ax2586:wrong>
</ns:return>
</ns:processResponse>
现在在网上搜索我已经构建了这个 XSLT 转换
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:template match="/">
<xsl:variable name="ns1" select="//*[local-name()='process']/*"/>
<xsl:variable name="ns2" select="//*[local-name()='good']/*"/>
<xsl:variable name="difference" select="$ns1[not(.=$ns2)],$ns2[not(.=$ns1)]"/>
<ax2586:wrong xmlns:ax2586="http://gamopera.ifpl.csi.it">
<ax2586:wrong><xsl:copy-of select="$difference"/></ax2586:wrong>
</ax2586:wrong>
</xsl:template>
</xsl:stylesheet>
这似乎工作正常,但尝试在网络上的不同 XSLT 测试器中使用它我发现它在某处工作而在某处不工作,所以我不太确定这是否是正确且可移植的解决方案。
注意:我必须在 WSO2 代理中使用它
有什么建议或替代方法可以获得相同的结果吗?
非常感谢您
切萨雷
【问题讨论】:
-
在其他 XSLT 引擎中运行它时遇到什么样的错误?那些引擎是什么?
-
freeformatter.com/xsl-transformer.html#ad-output --> 有效,xsltcake.com --> 无效,未显示错误,w3schools.com/xsl/… --> 无效,未显示错误,xslttest.appspot.com - -> 有效.....您可以尝试复制我的 XML 消息和 XSLT 转换...谢谢!