2013-05-13 2 views
1

아래 xml의 합계 금액에 대해 TXLifeRequest 아래에 추가 섹션을 추가해야한다는 요구 사항이 있습니다. PaymentAmt을 요약하는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> 

기준은 조합 TransExeDate , AccountNumber and ReversalInd을 찾는 것입니다. 난 내 아래 XSLT 그래서 내가 TXLifeRequest XML <TotalAmount>600</TotalAmount> 참조 요약 얻을 것이다 XSLT 위 적용한 후

<?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> 

을 PaymentAmt 적용 할 때 그래서 이러한 기준에 따라.

<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

답변

1

이 현재 XSL에 만에 작은 변화 : 스타일 :

<?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" 
    xmlns="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:variable name="vDataGroup" select= 
        "key('detKey7s', concat(generate-id(..),ns:TransExeDate, '+', ns:FundCode, '+', ns:ReversalInd))"/> 

       <xsl:copy> 

        <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:if test="count($vDataGroup) >1" > 
        <TXLifeRequest> 
         <SummedUP> 
          <xsl:value-of select=" ns:FundCode"/> 
         </SummedUP> 
        </TXLifeRequest> 
       </xsl:if> 

      </xsl:for-each> 
     </xsl:element> 
    </xsl:template> 
</xsl:stylesheet> 

다음과 같은 출력이 생성됩니다 :

<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> 
    <TotalAmount>300</TotalAmount> 
    </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> 
    <TotalAmount>600</TotalAmount> 
    </TXLifeRequest> 
    <TXLifeRequest> 
    <SummedUP>LTRW00</SummedUP> 
    </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> 
    <TotalAmount>800</TotalAmount> 
    </TXLifeRequest> 
</TXLife>