2013-06-23 104 views
0
<fo:block start-indent="5mm"> 
    <xsl:for-each select="//policyResult[not(AgentNumber=preceding-sibling::policyResult/AgentNumber)]" >  
    <xsl:variable name="agentNum"><xsl:value-of select="AgentNumber"></xsl:value-of> 
    </xsl:variable>     
    <xsl:for-each select="//policyResult[AgentNumber=$agentNum]">  
<xsl:sort select="agentnumber"/> 
<xsl:sort select="policynumber"/> 
    <fo:table border-style="" width="100%" border-spacing="4">       
    <fo:table-body>  
    <fo:table-row border-before-style="solid"> 
    <fo:table-cell> 
    <fo:block> 
      <fo:inline>Pol Number</fo:inline><xsl:value-of select="PolicyNumber"/>  
    </fo:block>  
    </fo:table-cell>   
    </fo:table-body>  
    </fo:table> 

我寫了這樣的代碼來過濾重複的節點。 這裏我的問題是我要解決這升序秩序。XML看起來像這樣基於排序的節點排序,分組和總和?

<policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
            <producttype>risk</producttype>       <PolicyNumber>003050669</PolicyNumber>  
        <AgentNumber>005262</AgentNumber> 
        <AnnualPremium>12000.0</AnnualPremium>     
    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
<producttype>wealth</producttype>     
<PolicyNumber>003050669</PolicyNumber> 
        <AgentNumber>005282</AgentNumber> 
        <AnnualPremium>12000.0</AnnualPremium>     
    </policyResult> 

    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
<producttype>risk</producttype> 
        <PolicyNumber>003050670</PolicyNumber> 
        <AgentNumber>005262</AgentNumber> 
        <AnnualPremium>12000.0</AnnualPremium>  

    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
<producttype>wealth</producttype> 
        <PolicyNumber>003050671</PolicyNumber> 
        <AgentNumber>005263</AgentNumber> 
        <AnnualPremium>12000.0</AnnualPremium>      
    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
<producttype>wealth</producttype> 
        <PolicyNumber>003050668</PolicyNumber> 
        <AgentNumber>005265</AgentNumber> 
        <AnnualPremium>12000.0</AnnualPremium>     
    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
<producttype>wealth</producttype> 
        <PolicyNumber>003050668</PolicyNumber> 
        <AgentNumber>005265</AgentNumber> 
        <AnnualPremium>12000.0</AnnualPremium>     
    </policyResult> 

什麼,我要做的是過濾AgentNumber,AnnualPremium升序order.and需要總結每個代理的Annualpremium和所有Annualpremium的總和。

輸出應該是這樣的。 如果代理 重複數,我們必須以升序只有一次顯示它

產品類型:風險

代理人數量005266

policynumber 003050669 anuual保費12000

policynumber 003050671 anuual溢價12000

總年度溢價 - 該代理人的保費總額,即240 00

代理人數量005267

policynumber 00 anuual保費11000

policynumber 00 anuual保費11000這個代理的保費 總年保費--sum即22000

產品類型:財富

代理商編號005266

policynumber 003050669 anuual保費12000

policynumber 003050671 anuual溢價這個代理的保費12000

總年保費--sum即24000

代理人數量005267

policynumber 00 anuual溢價11000

政策編號00 anuual保費11000 總年保費本劑溢價--sum即22000

末我們需要顯示所有代理的總年度保費

總保費24000 --- 22000 + 46000 =

請幫我out..thanks提前

需要這種輸出的..

回答

0

同樣,輸入數據不符合您的預期結果。今天我沒有時間來糾正你的輸入數據,但是我寫了一個可以處理糾正數據的變換。我用你給我的數據來運行它。

在嵌套分組的新XSLT 1.0要求中,我發現使用基於變量的分組方法是最簡單的。

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 

<xsl:output method="text"/> 

<xsl:template match="policies"> 
    <xsl:variable name="types" select="policyResult"/> 
    <xsl:for-each select="$types"> 
    <xsl:sort select="producttype"/> 
    <xsl:if test="generate-id(.)= 
        generate-id($types[producttype=current()/producttype][1])"> 
Product type: <xsl:value-of select="producttype"/> 
     <xsl:variable name="agents" 
        select="$types[producttype=current()/producttype]"/> 
     <xsl:for-each select="$agents"> 
     <xsl:sort select="AgentNumber"/> 
     <xsl:if test="generate-id(.)= 
        generate-id($agents[AgentNumber=current()/AgentNumber][1])"> 
Agent number: <xsl:value-of select="AgentNumber"/> 
      <xsl:for-each select="$agents[AgentNumber=current()/AgentNumber]"> 
Policy number: <xsl:value-of select="PolicyNumber"/> Premium: <xsl:value-of 
          select="AnnualPremium"/> 
      </xsl:for-each> 
Agent premium total: <xsl:value-of 
     select="sum($agents[AgentNumber=current()/AgentNumber]/AnnualPremium)"/> 
     </xsl:if> 
     </xsl:for-each> 
    </xsl:if> 
    </xsl:for-each> 
Premium total: <xsl:value-of select="sum(policyResult/AnnualPremium)"/> 
</xsl:template> 

</xsl:stylesheet> 

當樣式表應用到下面的XML:

<?xml version="1.0" encoding="UTF-8"?> 
<policies> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
    <producttype>risk</producttype> 
    <PolicyNumber>003050669</PolicyNumber> 
    <AgentNumber>005262</AgentNumber> 
    <AnnualPremium>12000.0</AnnualPremium> 
    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
    <producttype>wealth</producttype> 
    <PolicyNumber>003050669</PolicyNumber> 
    <AgentNumber>005282</AgentNumber> 
    <AnnualPremium>12000.0</AnnualPremium> 
    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
    <producttype>risk</producttype> 
    <PolicyNumber>003050670</PolicyNumber> 
    <AgentNumber>005262</AgentNumber> 
    <AnnualPremium>12000.0</AnnualPremium> 
    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
    <producttype>wealth</producttype> 
    <PolicyNumber>003050671</PolicyNumber> 
    <AgentNumber>005263</AgentNumber> 
    <AnnualPremium>12000.0</AnnualPremium> 
    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
    <producttype>wealth</producttype> 
    <PolicyNumber>003050668</PolicyNumber> 
    <AgentNumber>005265</AgentNumber> 
    <AnnualPremium>12000.0</AnnualPremium> 
    </policyResult> 
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant"> 
    <producttype>wealth</producttype> 
    <PolicyNumber>003050668</PolicyNumber> 
    <AgentNumber>005265</AgentNumber> 
    <AnnualPremium>12000.0</AnnualPremium> 
    </policyResult> 
</policies> 

它產生以下輸出:

Product type: risk 
Agent number: 005262 
Policy number: 003050669 Premium: 12000.0 
Policy number: 003050670 Premium: 12000.0 
Agent premium total: 24000 
Product type: wealth 
Agent number: 005263 
Policy number: 003050671 Premium: 12000.0 
Agent premium total: 12000 
Agent number: 005265 
Policy number: 003050668 Premium: 12000.0 
Policy number: 003050668 Premium: 12000.0 
Agent premium total: 24000 
Agent number: 005282 
Policy number: 003050669 Premium: 12000.0 
Agent premium total: 12000 
Premium total: 72000