标记前带有XSLT数据的XML转换



我试图将转换应用于有效负载,但结果有一些松散的值,我做错了什么?

起初,我对原始名称空间有问题,做了一些研究后发现我必须声明它,但现在这种情况发生了,我不理解它。我匹配pbc:operaciones,这样我就可以处理该数组中的数据,为什么它会显示其他值?

XML输入:

<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<PbcWsGetOperacionesResponse xmlns="http://ddpbc.cbc.es">
<estado>
<estado>OK</estado>
</estado>
<numeroOperaciones>67</numeroOperaciones>
<operaciones>
<operacion>
<codigoOperacion>E007O000121</codigoOperacion>
<codigoPromocion>E007P0007</codigoPromocion>
<nombrePromocion>101 - Altos de Los Fresnos</nombrePromocion>
<codigoCliente/>
<identificacionCliente>10011242M</identificacionCliente>
<cliente>JUAN LOPEZ</cliente>
<inmueble/>
<estado>2</estado>
<conclusion>5</conclusion>
<fechaConclusion>2020-08-27T11:39:51+02:00</fechaConclusion>
<numeroIntervinientes>1</numeroIntervinientes>
</operacion>
<operacion>
<codigoOperacion>E007O000122</codigoOperacion>
<codigoPromocion>E007P0007</codigoPromocion>
<nombrePromocion>101 - Altos de Los Fresnos</nombrePromocion>
<codigoCliente/>
<identificacionCliente>10011242M</identificacionCliente>
<cliente>JUAN LOPEZ</cliente>
<inmueble/>
<estado>2</estado>
<conclusion>5</conclusion>
<fechaConclusion>2020-08-27T11:40:02+02:00</fechaConclusion>
<numeroIntervinientes>1</numeroIntervinientes>
</operacion>
</operaciones>
</PbcWsGetOperacionesResponse>
</soap:Body>
</soap:Envelope>

XSLT-

<xsl:stylesheet version="1.0" xmlns:pbc="http://ddpbc.cbc.es" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:b="http://ws.wso2.org/dataservice" xmlns:xslFormatting="urn:xslFormatting">
<xsl:template match="pbc:operaciones">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soap:Body>
<urn:ZacCreaExpedientesFromWs>
<ItExpeout>
<xsl:for-each select="pbc:operacion">
<item>
<Expedien>
<xsl:value-of select="pbc:codigoOperacion"/>
</Expedien>
<Status>
<xsl:value-of select="pbc:conclusion"/>
</Status>
<Fexpedient>
<xsl:value-of select="pbc:fechaConclusion"/>
</Fexpedient>
</item>
</xsl:for-each>
</ItExpeout>
</urn:ZacCreaExpedientesFromWs>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>

结果:

<?xml version="1.0" encoding="UTF-8"?>



OK

67
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style" xmlns:pbc="http://ddpbc.cbc.es" xmlns:b="http://ws.wso2.org/dataservice" xmlns:xslFormatting="urn:xslFormatting"><soap:Body><urn:ZacCreaExpedientesFromWs><ItExpeout><item><Expedien>E007O000121</Expedien><Status>5</Status><Fexpedient>2020-08-27T11:39:51+02:00</Fexpedient></item><item><Expedien>E007O000122</Expedien><Status>5</Status><Fexpedient>2020-08-27T11:40:02+02:00</Fexpedient></item></ItExpeout></urn:ZacCreaExpedientesFromWs></soap:Body></soap:Envelope>


谢谢!

为什么显示其他值?

因为样式表只有一个匹配operaciones的模板。其他节点(即estadonumeroOperaciones(由内置的模板规则处理,这些规则将其文本值复制到输出中。

尝试:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:pbc="http://ddpbc.cbc.es"
exclude-result-prefixes="pbc">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soap:Body>
<urn:ZacCreaExpedientesFromWs>
<ItExpeout>
<xsl:for-each select="//pbc:operacion">
<item>
<Expedien>
<xsl:value-of select="pbc:codigoOperacion"/>
</Expedien>
<Status>
<xsl:value-of select="pbc:conclusion"/>
</Status>
<Fexpedient>
<xsl:value-of select="pbc:fechaConclusion"/>
</Fexpedient>
</item>
</xsl:for-each>
</ItExpeout>
</urn:ZacCreaExpedientesFromWs>
</soap:Body>
</soap:Envelope>
</xsl:template>

</xsl:stylesheet>

或者(最好是IMHO(:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:soap0="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:pbc="http://ddpbc.cbc.es"
exclude-result-prefixes="soap0 pbc">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/soap0:Envelope">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
<soap:Body>
<urn:ZacCreaExpedientesFromWs>
<ItExpeout>
<xsl:for-each select="soap0:Body/pbc:PbcWsGetOperacionesResponse/pbc:operaciones/pbc:operacion">
<item>
<Expedien>
<xsl:value-of select="pbc:codigoOperacion"/>
</Expedien>
<Status>
<xsl:value-of select="pbc:conclusion"/>
</Status>
<Fexpedient>
<xsl:value-of select="pbc:fechaConclusion"/>
</Fexpedient>
</item>
</xsl:for-each>
</ItExpeout>
</urn:ZacCreaExpedientesFromWs>
</soap:Body>
</soap:Envelope>
</xsl:template>

</xsl:stylesheet>

最新更新