Xml 使用XSLT转换使用XSLT/XPath提取子字符串(用于WSO2)
我是XSLT/XPath方面的新手 我收到了以下XML消息Xml 使用XSLT转换使用XSLT/XPath提取子字符串(用于WSO2),xml,xslt,xpath,wso2,Xml,Xslt,Xpath,Wso2,我是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
<?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>
1.
3.
5.
7.
438
2.
4.
6.
8.
1.
3.
5.
7.
我想得到像这样的东西
<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>
1.
3.
5.
7.
消息存储不存在。
0
438
2.
4.
6.
8.
现在在web上搜索,我已经构建了这个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>
这似乎工作得很好,但尝试在web上的不同XSLT测试仪中使用它时,我发现它在某些地方工作,而在某些地方不工作,因此我不太确定这是否是正确的可移植解决方案
注意:我必须在WSO2代理中使用它
是否有任何建议或替代方法可以获得相同的结果
事先非常感谢
Cesare
xsltcake.com
允许您使用不同的引擎运行XSLT。如果您选择了.NETXSLT引擎,则会出现以下错误
表达式应为结尾,找到“,”。System.Xml.Xsl.Xsl异常
这可能属于的唯一地方是以下XPath
$ns1[not(.=$ns2)],$ns2[not(.=$ns1)]
XSLT1.0中当然不允许这样做。看来你是说
$ns1[not(.=$ns2)]
在这种情况下,它真的很有效。实时版本:在其他XSLT引擎中运行时会出现什么样的错误?那些引擎是什么?-->起作用,-->不起作用,未显示错误,-->不起作用,未显示错误,-->起作用。。。。。您可以尝试复制我的XML消息和XSLT转换。。。谢谢您的意思是XPath$ns1[not(..=$ns2)],$ns2[not(..=$ns1)]是关于XSLT2.0的吗?在任何caso中,我都看到您的live版本在xsltcake.com中工作。。。。谢谢@塞萨尔。(也可以考虑接受一个答案,如果它有帮助的话)我在上面所有的引擎中都尝试过同样的XPath $NS1[不(.= $NS2)],现在它似乎无处不在。