这是输入 XML:
<deliveryStatusRequest>
<Partner>
<partyRoleId>A47422</partyRoleId>
<Banner>
<partyRoleId>A47423</partyRoleId>
<POS>
<partyRoleId>A47424</partyRoleId>
</POS>
<POS>
<partyRoleId>A47425</partyRoleId>
</POS>
</Banner>
<Banner>
<partyRoleId>A47426</partyRoleId>
<POS>
<partyRoleId>A47428</partyRoleId>
</POS>
</Banner>
</Partner>
<ProcessData>
<Partner>
<returnCode>00</returnCode>
<returnDescription>123456789</returnDescription>
<Banner>
<returnCode>00</returnCode>
<returnDescription>234567890</returnDescription>
<POS>
<returnCode>01</returnCode>
<returnDescription>Some error</returnDescription>
</POS>
<POS>
<returnCode>00</returnCode>
<returnDescription>456789012</returnDescription>
</POS>
</Banner>
<Banner>
<returnCode>00</returnCode>
<returnDescription>567890123</returnDescription>
<POS>
<returnCode>02</returnCode>
<returnDescription>Some Error</returnDescription>
</POS>
</Banner>
</Partner>
</ProcessData>
</deliveryStatusRequest>
这是预期的输出:
<SiebelMessage
MessageType="Integration Object"
IntObjectName="SFA Create Update Seller IO"
IntObjectFormat="Siebel Hierarchical">
<ListOfSfaCreateUpdateSellerIo>
<SfaSubAccountmasterBc>
<CodiceSFA/> <!--Mapped to PartyRowId-->
<CodiceSAP> <!--Mapped to returnDescription if returnCode is 00-->
<StatoSAP> <!--"Attivo" If returnCode is 00 -->
<StatoCommerciale> <!-- "Attivo" If returnCode is 00 else set to "Prospect"-->
<DescrizioneRitornoSAP> <!--Mapped to returnDescription if returnCode is not 00-->
<ListOfSfaSubaccountInsegnaBc>
<SfaSubaccountInsegnaBc>
<CodiceSFA/> <!--Mapped to PartyRowId-->
<CodiceSAP> <!--Mapped to returnDescription if returnCode is 00-->
<StatoSAP> <!--"Attivo" If returnCode is 00 -->
<StatoCommerciale> <!-- "Attivo" If returnCode is 00 else set to "Prospect"-->
<DescrizioneRitornoSAP> <!--Mapped to returnDescription if returnCode is not 00-->
<ListOfSfaSubaccountPdvBc>
<SfaSubaccountPdvBc>
<CodiceSFA/> <!--Mapped to PartyRowId-->
<CodiceSAP> <!--Mapped to returnDescription if returnCode is 00--
<StatoSAP> <!--"Attivo" If returnCode is 00 -->
<StatoCommerciale> <!-- "Attivo" If returnCode is 00 else set to "Prospect"-->
<DescrizioneRitornoSAP> <!--Mapped to returnDescription if returnCode is not 00-->
</SfaSubaccountPdvBc>
</ListOfSfaSubaccountPdvBc>
</SfaSubaccountInsegnaBc>
</ListOfSfaSubaccountInsegnaBc>
</SfaSubAccountmasterBc>
</ListOfSfaCreateUpdateSellerIo>
</SiebelMessage>
我已经创建了 XSLT,但是它不起作用:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="deliveryStatusRequest">
<SiebelMessage MessageType="Integration Object" IntObjectName="SFA Create Update Seller IO" IntObjectFormat="Siebel Hierarchical">
<ListOfSfaCreateUpdateSellerIo>
<xsl:apply-templates select="Partner"/>
</ListOfSfaCreateUpdateSellerIo>
</SiebelMessage>
</xsl:template>
<xsl:template match="Partner">
<SfaSubAccountmasterBc>
<CodiceSFA><xsl:value-of select="partyRoleId"/></CodiceSFA>
<CodiceSAP>
<xsl:if test="../ProcessData/Partner/returnCode = '00'">
<xsl:value-of select="../ProcessData/Partner/returnDescription"/>
</xsl:if>
</CodiceSAP>
<StatoSAP>
<xsl:if test="../ProcessData/Partner/returnCode = '00'">Attivo</xsl:if>
</StatoSAP>
<StatoCommerciale>
<xsl:choose>
<xsl:when test="../ProcessData/Partner/returnCode = '00'">Attivo</xsl:when>
<xsl:otherwise>Prospect</xsl:otherwise>
</xsl:choose>
</StatoCommerciale>
<DescrizioneRitornoSAP>
<xsl:if test="../ProcessData/Partner/returnCode != '00'">
<xsl:value-of select="../ProcessData/Partner/returnDescription"/>
</xsl:if>
</DescrizioneRitornoSAP>
<ListOfSfaSubaccountInsegnaBc>
<xsl:apply-templates select="Banner"/>
</ListOfSfaSubaccountInsegnaBc>
</SfaSubAccountmasterBc>
</xsl:template>
<xsl:template match="Banner">
<SfaSubaccountInsegnaBc>
<CodiceSFA><xsl:value-of select="partyRoleId"/></CodiceSFA>
<xsl:variable name="bannerIndex" select="count(preceding-sibling::Banner) + 1"/>
<CodiceSAP>
<xsl:if test="../../ProcessData/Partner/Banner[$bannerIndex]/returnCode = '00'">
<xsl:value-of select="../../ProcessData/Partner/Banner[$bannerIndex]/returnDescription"/>
</xsl:if>
</CodiceSAP>
<StatoSAP>
<xsl:if test="../../ProcessData/Partner/Banner[$bannerIndex]/returnCode = '00'">Attivo</xsl:if>
</StatoSAP>
<StatoCommerciale>
<xsl:choose>
<xsl:when test="../../ProcessData/Partner/Banner[$bannerIndex]/returnCode = '00'">Attivo</xsl:when>
<xsl:otherwise>Prospect</xsl:otherwise>
</xsl:choose>
</StatoCommerciale>
<DescrizioneRitornoSAP>
<xsl:if test="../../ProcessData/Partner/Banner[$bannerIndex]/returnCode != '00'">
<xsl:value-of select="../../ProcessData/Partner/Banner[$bannerIndex]/returnDescription"/>
</xsl:if>
</DescrizioneRitornoSAP>
<ListOfSfaSubaccountPdvBc>
<xsl:apply-templates select="POS"/>
</ListOfSfaSubaccountPdvBc>
</SfaSubaccountInsegnaBc>
</xsl:template>
<xsl:template match="POS">
<SfaSubaccountPdvBc>
<CodiceSFA><xsl:value-of select="partyRoleId"/></CodiceSFA>
<xsl:variable name="bannerIndex" select="count(../../preceding-sibling::Banner) + 1"/>
<xsl:variable name="posIndex" select="count(preceding-sibling::POS) + 1"/>
<CodiceSAP>
<xsl:if test="../../../../ProcessData/Partner/Banner[$bannerIndex]/POS[$posIndex]/returnCode = '00'">
<xsl:value-of select="../../../../ProcessData/Partner/Banner[$bannerIndex]/POS[$posIndex]/returnDescription"/>
</xsl:if>
</CodiceSAP>
<StatoSAP>
<xsl:if test="../../../../ProcessData/Partner/Banner[$bannerIndex]/POS[$posIndex]/returnCode = '00'">Attivo</xsl:if>
</StatoSAP>
<StatoCommerciale>
<xsl:choose>
<xsl:when test="../../../../ProcessData/Partner/Banner[$bannerIndex]/POS[$posIndex]/returnCode = '00'">Attivo</xsl:when>
<xsl:otherwise>Prospect</xsl:otherwise>
</xsl:choose>
</StatoCommerciale>
<DescrizioneRitornoSAP>
<xsl:if test="../../../../ProcessData/Partner/Banner[$bannerIndex]/POS[$posIndex]/returnCode != '00'">
<xsl:value-of select="../../../../ProcessData/Partner/Banner[$bannerIndex]/POS[$posIndex]/returnDescription"/>
</xsl:if>
</DescrizioneRitornoSAP>
</SfaSubaccountPdvBc>
</xsl:template>
</xsl:stylesheet>
我得到了这样的输出,在 POS 下它没有正确映射输出。它甚至没有将 ReturnDescription 映射到 Description 标签。
<?xml version="1.0" encoding="UTF-8"?>
<SiebelMessage MessageType="Integration Object"
IntObjectName="SFA Create Update Seller IO"
IntObjectFormat="Siebel Hierarchical">
<ListOfSfaCreateUpdateSellerIo>
<SfaSubAccountmasterBc>
<CodiceSFA>A47422</CodiceSFA>
<CodiceSAP>123456789</CodiceSAP>
<StatoSAP>Attivo</StatoSAP>
<StatoCommerciale>Attivo</StatoCommerciale>
<DescrizioneRitornoSAP/>
<ListOfSfaSubaccountInsegnaBc>
<SfaSubaccountInsegnaBc>
<CodiceSFA>A47423</CodiceSFA>
<CodiceSAP>234567890</CodiceSAP>
<StatoSAP>Attivo</StatoSAP>
<StatoCommerciale>Attivo</StatoCommerciale>
<DescrizioneRitornoSAP/>
<ListOfSfaSubaccountPdvBc>
<SfaSubaccountPdvBc>
<CodiceSFA>A47424</CodiceSFA>
<CodiceSAP/>
<StatoSAP/>
<StatoCommerciale>Prospect</StatoCommerciale>
<DescrizioneRitornoSAP/>
</SfaSubaccountPdvBc>
<SfaSubaccountPdvBc>
<CodiceSFA>A47425</CodiceSFA>
<CodiceSAP/>
<StatoSAP/>
<StatoCommerciale>Prospect</StatoCommerciale>
<DescrizioneRitornoSAP/>
</SfaSubaccountPdvBc>
</ListOfSfaSubaccountPdvBc>
</SfaSubaccountInsegnaBc>
<SfaSubaccountInsegnaBc>
<CodiceSFA>A47426</CodiceSFA>
<CodiceSAP>567890123</CodiceSAP>
<StatoSAP>Attivo</StatoSAP>
<StatoCommerciale>Attivo</StatoCommerciale>
<DescrizioneRitornoSAP/>
<ListOfSfaSubaccountPdvBc>
<SfaSubaccountPdvBc>
<CodiceSFA>A47428</CodiceSFA>
<CodiceSAP/>
<StatoSAP/>
<StatoCommerciale>Prospect</StatoCommerciale>
<DescrizioneRitornoSAP/>
</SfaSubaccountPdvBc>
</ListOfSfaSubaccountPdvBc>
</SfaSubaccountInsegnaBc>
</ListOfSfaSubaccountInsegnaBc>
</SfaSubAccountmasterBc>
</ListOfSfaCreateUpdateSellerIo>
</SiebelMessage>
逻辑如下:POS 的 CodiceSAP:如果 returnCode = '00',则填充 CodiceSAP。POS 的 DescrizioneRitornoSAP:仅当 returnCode != '00' 时填充。POS 的 StatoSAP 和 StatoCommerciale:当 returnCode = '00' 时设置为 Attivo;否则,默认为“”(StatoSAP)和“Prospect”(对于 StatoCommerciale)。