1
我有要求在TXLifeRequest
下增加一個額外部分,以便從下面的xml中總結付款金額。xslt根據元素組合總結
<?xml version="1.0" encoding="utf-8"?>
<TXLife xmlns="http://ACORD.org/Standards/Life/2">
<TXLifeRequest>
<FundCode>LTRT00</FundCode>
<AccountDescription>CWA xxx</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>300.000000000</PaymentAmt>
<ReversalInd>0</ReversalInd>
</TXLifeRequest>
<TXLifeRequest>
<FundCode>LTRW00</FundCode>
<AccountDescription>CWA xxx</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>300.000000000</PaymentAmt>
<ReversalInd>0</ReversalInd>
</TXLifeRequest>
<TXLifeRequest>
<FundCode>LTRW00</FundCode>
<AccountDescription>CWA xxx</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>300.000000000</PaymentAmt>
<ReversalInd>0</ReversalInd>
</TXLifeRequest>
<TXLifeRequest>
<FundCode>LUL500</FundCode>
<AccountDescription>CWA xxx</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>800.000000000</PaymentAmt>
<ReversalInd>1</ReversalInd>
</TXLifeRequest>
</TXLife>
總結PaymentAmt的標準是尋找組合TransExeDate , AccountNumber and ReversalInd
。所以,基於這些標準時,我運用我下面的XSLT因此應用上面的XSLT我會總結TXLifeRequest
XML看到<TotalAmount>600</TotalAmount>
後PaymentAmt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:ns="http://ACORD.org/Standards/Life/2">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="detKey7s" match="//ns:TXLifeRequest"
use="concat(generate-id(..), ns:TransExeDate, '+', ns:FundCode, '+', ns:ReversalInd)"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ns:TXLife">
<xsl:element name="TXLife" namespace="http://ACORD.org/Standards/Life/2">
<xsl:for-each select="ns:TXLifeRequest[generate-id() = generate-id(key('detKey7s',
concat(generate-id(..), ns:TransExeDate, '+', ns:FundCode, '+', ns:ReversalInd)
)
)
]
">
<xsl:copy>
<xsl:variable name="vDataGroup" select=
"key('detKey7s', concat(generate-id(..),ns:TransExeDate, '+', ns:FundCode, '+', ns:ReversalInd))"/>
<xsl:apply-templates select="./*"></xsl:apply-templates>
<xsl:element name="TotalAmount" namespace="http://ACORD.org/Standards/Life/2">
<xsl:value-of select="sum($vDataGroup/ns:PaymentAmt)"/>
</xsl:element>
</xsl:copy>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
。
<TXLife xmlns="http://ACORD.org/Standards/Life/2">
<TXLifeRequest>
<FundCode>LTRT00</FundCode>
<AccountDescription>CWA – NB+U</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>300.000000000</PaymentAmt>
<ReversalInd>0</ReversalInd>
<TotalAmount>300</TotalAmount>
</TXLifeRequest>
<TXLifeRequest>
<FundCode>LTRW00</FundCode>
<AccountDescription>CWA – NB+U</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>300.000000000</PaymentAmt>
<ReversalInd>0</ReversalInd>
<TotalAmount>600</TotalAmount>
</TXLifeRequest>
<TXLifeRequest>
<FundCode>LUL500</FundCode>
<AccountDescription>CWA – NB+U</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>800.000000000</PaymentAmt>
<ReversalInd>1</ReversalInd>
<TotalAmount>800</TotalAmount>
</TXLifeRequest>
</TXLife>
現在的問題是如何在總結部分下添加額外的部分?所以最後xml應該看起來如下所述
<TXLifeRequest>
<FundCode>LTRT00</FundCode>
<AccountDescription>CWA – NB+U</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>300.000000000</PaymentAmt>
<ReversalInd>0</ReversalInd>
<TotalAmount>300</TotalAmount>
</TXLifeRequest>
<TXLifeRequest>
<FundCode>LTRW00</FundCode>
<AccountDescription>CWA – NB+U</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>300.000000000</PaymentAmt>
<ReversalInd>0</ReversalInd>
<TotalAmount>600</TotalAmount>
</TXLifeRequest>
<TXLifeRequest>
<SummedUP>LTRW00</SummedUP>
</TXLifeRequest>
<TXLifeRequest>
<FundCode>LUL500</FundCode>
<AccountDescription>CWA – NB+U</AccountDescription>
<CurrencyTypeCode>840</CurrencyTypeCode>
<TransExeDate>2013-04-20</TransExeDate>
<AccountNumber>34142</AccountNumber>
<PaymentAmt>800.000000000</PaymentAmt>
<ReversalInd>1</ReversalInd>
<TotalAmount>800</TotalAmount>
</TXLifeRequest>
我感到驚訝的是在上面提到的總結部分之後添加一個部分。請讓我知道我如何繼續。有任何想法嗎 ??
感謝, 馬杜CM