私は XSLT に比較的慣れておらず、比較的単純であるべきものに大きな問題を抱えています。2 日間インターネットを検索しましたが、この問題の最後のハードルを乗り越えることができません。
変換したい XML の単純なバージョンを次に示します。
<Payment xmlns="http://www.xxxxxx.com/CIB/GIFTS/PaymentFileSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xxxxxx.com/CIB/GIFTS/PaymentFileSchema.xsd ">
<Transaction>
<POSellerName>DAF KNITWEARS LTD. (PG)</POSellerName>
<PayeeName>883456789</PayeeName>
<CurrencyCode>USD</CurrencyCode>
<WTLCNumber>O0910122</WTLCNumber>
<VendorAppNumber>6031</VendorAppNumber>
<DocumentNumber>BEAI12000094</DocumentNumber>
<PODetail>
<PONumber>0887537</PONumber>
<QuantityShipped>2550</QuantityShipped>
<UnitOfMeasure>PCS</UnitOfMeasure>
<CurrencyCode>USD</CurrencyCode>
<AmountBilled>13226.37</AmountBilled>
</PODetail>
<PODetail>
<PONumber>0887567</PONumber>
<QuantityShipped>150</QuantityShipped>
<UnitOfMeasure>PCS</UnitOfMeasure>
<CurrencyCode>USD</CurrencyCode>
<AmountBilled>873</AmountBilled>
</PODetail>
<ChargeBackDetail>
<PONumber>0887567</PONumber>
<CurrencyCode>USD</CurrencyCode>
<ChargeBackAllocationAmount>-105</ChargeBackAllocationAmount>
<ChargeBackReferenceNumber>CB0872364C</ChargeBackReferenceNumber>
<UPC/>
</ChargeBackDetail>
<ChargeBackDetail>
<PONumber>0872355</PONumber>
<CurrencyCode>USD</CurrencyCode>
<ChargeBackAllocationAmount>-105</ChargeBackAllocationAmount>
<ChargeBackReferenceNumber>CB0872355A</ChargeBackReferenceNumber>
<UPC/>
</ChargeBackDetail>
</Transaction>
</Payment>
<PODetail>
名前付きの各要素の最後に要素を挿入したい
<AmountPaid>.
そのため、それぞれを処理し、それぞれの要素で同じ値を持つ<PODetail>
を探します。<ChargeBackDetail>
見つかった場合、要素は /PODetail/Amountbilled - /ChargeBackDetail/ChargeBackAllocationAmount の値を持ち、それ以外の場合、値は /PODetail/Amountbilled と等しくなります。以下は、PONumber 要素の望ましい結果です。
<PODetail>
<PONumber>0887537</PONumber>
<QuantityShipped>2550</QuantityShipped>
<UnitOfMeasure>PCS</UnitOfMeasure>
<CurrencyCode>USD</CurrencyCode>
<AmountBilled>13226.37</AmountBilled>
<AmountPaid>13226.37</AmountPaid>
</PODetail>
<PODetail>
<PONumber>0887567</PONumber>
<QuantityShipped>150</QuantityShipped>
<UnitOfMeasure>PCS</UnitOfMeasure>
<CurrencyCode>USD</CurrencyCode>
<AmountBilled>873</AmountBilled>
<AmountPaid>768</AmountPaid>
</PODetail>
これは私のXSLTです:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pf="http://www.WellsFargo.com/CIB/GIFTS/TradeERP/PaymentFileSchema">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="pf:PODetail">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<xsl:variable name="poNumber" select="pf:PONumber"/>
<xsl:variable name="poAmountBilled" select="number(pf:AmountBilled)"/>
<xsl:for-each select="//pf:Transaction/pf:ChargeBackDetail">
<xsl:variable name="poNumber" select="pf:PODetail/pf:PONumber"/>
<xsl:variable name="cbPONumber" select="./pf:ChargeBackDetail/pf:PONumber"/>
<xsl:variable name="cbAmount" select="number(./pf:ChargeBackDetail/pf:ChargeBackAllocationAmount)"/>
<xsl:if test='$poNumber = $cbPONumber'>
<AmountPaid><xsl:number value="$poAmountBilled - $cbAmount"/></AmountPaid>
</xsl:if>
</xsl:for-each>
<xsl:if test ="not(pf:AmountPaid)">
<AmountPaid><xsl:number value="$poAmountBilled"/> </AmountPaid>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
どんな助けでも大歓迎です!
遺伝子