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。并且需要将每个代理的年费和所有年费的总和相加。

输出应该是这样的。如果代理编号重复,我们只需按升序显示一次

产品类型:风险

代理编号 005266

保单号 003050669 年保费 12000

保单号 003050671 年保费 12000

年度总保费--该代理人的保费总和即24000

代理编号 005267

保单号 0001234 年保费 11000

保单编号 0001235 年度保费 11000 年度总保费 -- 该代理人的保费总和即 22000

产品类型:财富

代理编号 005266

保单号 003050669 年保费 12000

保单号 003050671 年保费 12000

年度总保费--该代理人的保费总和即24000

代理编号 005267

保单号 0001234 年保费 11000

保单编号 0001235 年度保费 11000 年度总保费 -- 该代理人的保费总和即 22000

最后,我们需要显示所有代理商的整体年度保费

总保费---24000+22000=46000

请帮帮我..提前谢谢

需要这种输出..

4

1 回答 1

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
于 2013-06-23T13:40:29.923 回答