这是输入 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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<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:choose>
<xsl:when test="../ProcessData/Partner/returnCode = '00'">
<xsl:value-of select="../ProcessData/Partner/returnDescription"/>
</xsl:when>
</xsl:choose>
</CodiceSAP>
<StatoSAP>Attivo</StatoSAP>
<StatoCommerciale>Attivo</StatoCommerciale>
<DescrizioneRitornoSAP/>
<ListOfSfaSubaccountInsegnaBc>
<xsl:apply-templates select="Banner"/>
</ListOfSfaSubaccountInsegnaBc>
</SfaSubAccountmasterBc>
</xsl:template>
<xsl:template match="Banner">
<SfaSubaccountInsegnaBc>
<CodiceSFA>
<xsl:value-of select="partyRoleId"/>
</CodiceSFA>
<CodiceSAP>
<xsl:choose>
<xsl:when test="../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnCode = '00'">
<xsl:value-of select="../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnDescription"/>
</xsl:when>
</xsl:choose>
</CodiceSAP>
<StatoSAP>Attivo</StatoSAP>
<StatoCommerciale>Attivo</StatoCommerciale>
<DescrizioneRitornoSAP>
<xsl:choose>
<xsl:when test="../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnCode != '00'">
<xsl:value-of select="../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnDescription"/>
</xsl:when>
</xsl:choose>
</DescrizioneRitornoSAP>
<ListOfSfaSubaccountPdvBc>
<xsl:apply-templates select="POS"/>
</ListOfSfaSubaccountPdvBc>
</SfaSubaccountInsegnaBc>
</xsl:template>
<xsl:template match="POS">
<SfaSubaccountPdvBc>
<CodiceSFA>
<xsl:value-of select="partyRoleId"/>
</CodiceSFA>
<CodiceSAP>
<xsl:choose>
<xsl:when test="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnCode = '00'">
<xsl:value-of select="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnDescription"/>
</xsl:when>
</xsl:choose>
</CodiceSAP>
<StatoSAP>
<xsl:choose>
<xsl:when test="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnCode = '00'">Attivo</xsl:when>
</xsl:choose>
</StatoSAP>
<StatoCommerciale>
<xsl:choose>
<xsl:when test="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnCode = '00'">Attivo</xsl:when>
<xsl:otherwise>Prospect</xsl:otherwise>
</xsl:choose>
</StatoCommerciale>
<DescrizioneRitornoSAP>
<xsl:choose>
<xsl:when test="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnCode != '00'">
<xsl:value-of select="../../../../ProcessData/Partner/Banner[position() = count(../../preceding-sibling::Banner) + 1]/POS[position() = count(preceding-sibling::POS) + 1]/returnDescription"/>
</xsl:when>
</xsl:choose>
</DescrizioneRitornoSAP>
</SfaSubaccountPdvBc>
</xsl:template>
</xsl:stylesheet>
我得到这样的输出,codiceSAP 没有填充所有实体:
<?xml version="1.0"?>
<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/>
<StatoSAP>Attivo</StatoSAP>
<StatoCommerciale>Attivo</StatoCommerciale>
<DescrizioneRitornoSAP/>
<ListOfSfaSubaccountPdvBc>
<SfaSubaccountPdvBc>
<CodiceSFA>A47424</CodiceSFA>
<CodiceSAP/>
<StatoSAP>Prospect</StatoSAP>
<StatoCommerciale/>
<DescrizioneRitornoSAP/>
</SfaSubaccountPdvBc>
<SfaSubaccountPdvBc>
<CodiceSFA>A47425</CodiceSFA>
<CodiceSAP/>
<StatoSAP>Prospect</StatoSAP>
<StatoCommerciale/>
<DescrizioneRitornoSAP/>
</SfaSubaccountPdvBc>
</ListOfSfaSubaccountPdvBc>
</SfaSubaccountInsegnaBc>
<SfaSubaccountInsegnaBc>
<CodiceSFA>A47426</CodiceSFA>
<CodiceSAP/>
<StatoSAP>Attivo</StatoSAP>
<StatoCommerciale>Attivo</StatoCommerciale>
<DescrizioneRitornoSAP/>
<ListOfSfaSubaccountPdvBc>
<SfaSubaccountPdvBc>
<CodiceSFA>A47428</CodiceSFA>
<CodiceSAP/>
<StatoSAP>Prospect</StatoSAP>
<StatoCommerciale/>
<DescrizioneRitornoSAP/>
</SfaSubaccountPdvBc>
</ListOfSfaSubaccountPdvBc>
</SfaSubaccountInsegnaBc>
</ListOfSfaSubaccountInsegnaBc>
</SfaSubAccountmasterBc>
</ListOfSfaCreateUpdateSellerIo>
</SiebelMessage>
逻辑是这样的: CodiceSAP for POS:如果 returnCode = '00',则填充 CodiceSAP。 POS 的 RitornoSAP 描述:仅当 returnCode != '00' 时才填充。 StatoSAP 和 StatoCommerciale for POS:当 returnCode = '00' 时设置为 Attivo;否则,默认“” (StatoSAP) 和“Prospect”(对于 StatoCommerciale)。
我认为您需要向上移动一级
..
才能填充CodiceSAP
,例如
<xsl:template match="Banner">
<SfaSubaccountInsegnaBc>
<CodiceSFA>
<xsl:value-of select="partyRoleId"/>
</CodiceSFA>
<CodiceSAP>
<xsl:choose>
<xsl:when test="../../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnCode = '00'">
<xsl:value-of select="../../ProcessData/Partner/Banner[position() = count(preceding-sibling::Banner) + 1]/returnDescription"/>
</xsl:when>
</xsl:choose>
</CodiceSAP>