xsl分组,排序和求和,总和..?

时间:2013-06-24 17:08:11

标签: xslt xslt-1.0

<GetPolicyStatus>
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant">
                    <PolicyNumber>445</PolicyNumber>                
                    <AnnualPremium>12000.0</AnnualPremium>
                    <AgentNumber>1</AgentNumber>
                    <ProductType>1</ProductType>
                    <PendingIssues>yes</PendingIssues>                      
    </policyResult>
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant">
                    <PolicyNumber>555</PolicyNumber>                
                    <AnnualPremium>12000.0</AnnualPremium>
                    <AgentNumber>2</AgentNumber>
                    <ProductType>1</ProductType>
                    <AfterBusinessIssues>yes</AfterBusinessIssues>                      
    </policyResult>
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant">
                    <PolicyNumber>446</PolicyNumber>                
                    <AnnualPremium>12000.0</AnnualPremium>
                    <AgentNumber>1</AgentNumber>
                    <ProductType>1</ProductType>
                    <PendingIssues>yes</PendingIssues>                      
    </policyResult>
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant">
                    <PolicyNumber>556</PolicyNumber>                
                    <AnnualPremium>12000.0</AnnualPremium>
                    <AgentNumber>2</AgentNumber>
                    <ProductType>1</ProductType>
                    <AfterBusinessIssues>yes</AfterBusinessIssues>                      
    </policyResult>
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant">
                    <PolicyNumber>447</PolicyNumber>                
                    <AnnualPremium>12000.0</AnnualPremium>
                    <AgentNumber>1</AgentNumber>
                    <ProductType>1</ProductType>
                    <PendingIssues>yes</PendingIssues>                      
    </policyResult>
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant">
                    <PolicyNumber>557</PolicyNumber>                
                    <AnnualPremium>12000.0</AnnualPremium>
                    <AgentNumber>2</AgentNumber>
                    <ProductType>1</ProductType>
                    <AfterBusinessIssues>yes</AfterBusinessIssues>                      
    </policyResult>
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant">
                    <PolicyNumber>448</PolicyNumber>                
                    <AnnualPremium>12000.0</AnnualPremium>
                    <AgentNumber>1</AgentNumber>
                    <ProductType>1</ProductType>
                    <PendingIssues>yes</PendingIssues>                      
    </policyResult>
    <policyResult xmlns="" xmlns:ns2="http://ws.faithlife.com/resonant">
                    <PolicyNumber>558</PolicyNumber>                
                    <AnnualPremium>12000.0</AnnualPremium>
                    <AgentNumber>2</AgentNumber>
                    <ProductType>1</ProductType>
                    <AfterBusinessIssues>yes</AfterBusinessIssues>                      
    </policyResult>

    </GetPolicyStatus>

这是我输入的xml,期待输出如下。

agent number :1 (sorted order)  
PendingIssues:yes(if yes)

product type: 1

policy number:445(sorted order)
annual premium:12000.0

policy number:446
annual premium:12000.0

sub total pending:24000(12000+12000)        

PendingIssues:yes(if yes)
product type: 2

policy number:555
annual premium:12000.0

policy number:556
annual premium:12000.0

sub total pending:24000(12000+12000)


AfterBusinessIssues:yes(if yes)

product type: 1

policy number:445
annual premium:12000.0

policy number:446
annual premium:12000.0

sub total after business:24000(12000+12000) 

AfterBusinessIssuess:yes(if yes)            

product type: 2

policy number:445
annual premium:12000.0

policy number:446
annual premium:12000.0

sub total after business:24000(12000+12000).

应该为所有代理人数重复一次。

grand total :sub total pending(all)+sub total after business(all)=24000(12000+12000)+24000(12000+12000)=48000

这里的代理人编号和政策编号应该按照排序顺序。我发布了同样的xml.i得到了答案,但现在对我来说有些挑战,请任何人帮助我。

分享xsl请在我做错的地方进行更正。谢谢你。

<xsl:template match="/">
        <xsl:variable name="types" select="//policyResult"></xsl:variable>



                <xsl:for-each select="$types">              

                    <xsl:sort select="ProductType"/>                    
                    <xsl:if test="generate-id(.)=generate-id($types[ProductType=current()/ProductType][1])">
                    <xsl:value-of select="ProductType"></xsl:value-of>
                    <xsl:variable name="agents" select="$types[ProductType=current()/ProductType]"></xsl:variable>
                    <xsl:for-each select="$agents">
                    <xsl:sort select="PolicyNumber"/>
                    <xsl:if test="generate-id(.)=generate-id($agents[AgentNumber=current()/AgentNumber][1])">

                    <fo:table border-style="" width="100%" border-spacing="4">
                        <fo:table-body>

                            <fo:table-row border-left-style="solid" border-right-style="solid" border-after-style="solid">
                                <fo:table-cell>
                                    <fo:block font-family="arial" font-size="10pt"
                                        font-weight="normal">
                                        <fo:inline>
                                            FR#:<xsl:value-of select="AgentNumber"></xsl:value-of>
                                        </fo:inline>
                                    </fo:block>
                                </fo:table-cell>                                
                            </fo:table-row>
                            </fo:table-body>
                        </fo:table>             


                    <xsl:for-each select="$agents[AgentNumber=current()/AgentNumber]">

                    <fo:block>
                        <xsl:text>&#160;</xsl:text>
                    </fo:block> 

                    <fo:block>
                        <xsl:text>&#160;</xsl:text>
                    </fo:block>             

                    <fo:table border-style="" width="100%" border-spacing="4">
                        <fo:table-column column-width="25%" />
                        <fo:table-column column-width="25%" />
                        <fo:table-column column-width="25%" />
                        <fo:table-column column-width="25%" />
                        <fo:table-body>
                            <fo:table-row border-before-style="solid" border-left-style="solid" border-right-style="solid">
                                <fo:table-cell>
                                    <fo:block font-family="arial" font-size="10pt"
                                        font-weight="normal">
                                        <fo:inline>
                                            Pol Number
                                        </fo:inline>
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell>
                                    <fo:block font-family="arial" font-size="10pt"
                                        font-weight="normal">
                                        <fo:inline text-decoration="underline">
                                            <xsl:value-of select="PolicyNumber"></xsl:value-of>---<xsl:value-of select="ProductType"></xsl:value-of>
                                        </fo:inline>
                                    </fo:block>
                                </fo:table-cell>

                            </fo:table-row>
                            <fo:table-row border-left-style="solid" border-right-style="solid">
                                <fo:table-cell>
                                    <fo:block font-family="arial" font-size="10pt"
                                        font-weight="normal">
                                        <fo:inline>
                                            Annual Premium
                                        </fo:inline>
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell>
                                    <fo:block font-family="arial" font-size="10pt"
                                        font-weight="normal">
                                        <fo:inline>
                                            $<xsl:value-of select="AnnualPremium"></xsl:value-of>
                                        </fo:inline>
                                    </fo:block>
                                </fo:table-cell>                                                                
                            </fo:table-row> 

                        </fo:table-body>
                        </fo:table>         

                        </xsl:for-each>
                        <fo:table border-style="solid" width="100%" border-spacing="4">
                        <fo:table-body>
                            <fo:table-row border-after-style="solid">
                                <fo:table-cell text-align="right">
                                    <fo:block font-family="arial" font-size="10pt"
                                        font-weight="normal">
                                        <fo:inline> 
                                        Annual Premium SubTotal
                                        </fo:inline>
                                    </fo:block>
                                </fo:table-cell>                

                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell border-right-style="solid">

                                <fo:block font-family="arial" font-size="10pt"
                                        font-weight="normal">
                                        <fo:inline> 

                                        Pending Business    

                                        </fo:inline>
                        </fo:block>
                                </fo:table-cell>
                            <fo:table-cell>

                                <fo:block font-family="arial" font-size="10pt" text-align="center"
                                        font-weight="normal">
                                        <fo:inline><!--                 
                                        $<xsl:value-of select="sum(//policyResult[AgentNumber=$agentNum]/AnnualPremium)"></xsl:value-o  

                                                            -->
                                        $<xsl:value-of select="sum($agents[AgentNumber=current()/AgentNumber]/AnnualPremium)"></xsl:value-of>
                                        </fo:inline>
                        </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-body>                        
                        </fo:table>

                        </xsl:if>

                        </xsl:for-each>
                        </xsl:if>

                        </xsl:for-each>


                    <fo:block>
                        <xsl:text>&#160;</xsl:text>
                    </fo:block>
                <fo:block id="last-page"/>                                  


    </xsl:template>

0 个答案:

没有答案