组合XSLT 1.0中的Sum&不同价值的数量

时间:2016-01-12 07:00:55

标签: xml text xslt-1.0 grouping distinct-values

我想使用XSLT 1.0在Current-Group中实现Group by功能...我已经设法基于" Organization"来获得顶级分组,但是使用&#中的子组34;盖&#34 ;;我失败了:(

http://xsltransform.net/pPzifpL/16)有XML&目前使用的是XSLT设置。

我还需要应用Sum(Current-Group()/ SumInsured)和不同(Addenda)的计数,但1.0不支持这个...请帮助我专家。

预期输出:(文字)

Client Sum Insured Report

UK
SNo.    Policy Number   Customer Name   Cover Note #    No. of Addendas Sum Insured Total Commission
 1       POL1           ABC             50242           2               40000       65
 2       POL2           XYZ             12345           1               30000       30
Totals :                                                                70000       95

US
SNo.    Policy Number   Customer Name   Cover Note #    No. of Addendas Sum Insured Total Commission
 1                      JKL             45678           0               10000       10
Totals :                                                                10000       10

XML:

<?xml version="1.0" encoding="UTF-8"?><?Siebel-Property-Set EscapeNames="true"?><SiebelMessage MessageId="1-OC05" IntObjectName="Client Sum Insured Report IO" MessageType="Integration Object" IntObjectFormat="Siebel Hierarchical">
<ListOfClientSumInsuredReportIo>
    <GroupPolicies>
     <Addenda>50242-1</Addenda>
     <CommAmt>50</CommAmt>
     <Cover>50242</Cover>
     <Customer>ABC</Customer>
     <Policy>POL1</Policy>
     <SumInsured>10000</SumInsured>
     <Organization>UK</Organization>
    </GroupPolicies>
    <GroupPolicies>
     <Addenda>50242-2</Addenda>
     <CommAmt>5</CommAmt>
     <Cover>50242</Cover>
     <Customer>ABC</Customer>
     <Policy>POL1</Policy>
     <SumInsured>20000</SumInsured>
     <Organization>UK</Organization>
    </GroupPolicies>
    <GroupPolicies>
     <Addenda></Addenda>
     <CommAmt>10</CommAmt>
     <Cover>50242</Cover>
     <Customer>ABC</Customer>
     <Policy>POL1</Policy>
     <SumInsured>10000</SumInsured>
     <Organization>UK</Organization>
    </GroupPolicies>
    <GroupPolicies>
     <Addenda>12345-1</Addenda>
     <CommAmt>20</CommAmt>
     <Cover>12345</Cover>
     <Customer>XYZ</Customer>
     <Policy>POL2</Policy>
     <SumInsured>20000</SumInsured>
     <Organization>UK</Organization>
    </GroupPolicies>
    <GroupPolicies>
     <Addenda></Addenda>
     <CommAmt>10</CommAmt>
     <Cover>12345</Cover>
     <Customer>XYZ</Customer>
     <Policy>POL2</Policy>
     <SumInsured>10000</SumInsured>
     <Organization>UK</Organization>
    </GroupPolicies>
    <GroupPolicies>
     <Addenda></Addenda>
     <CommAmt>10</CommAmt>
     <Cover>45678</Cover>
     <Customer>JKL</Customer>
     <Policy></Policy>
     <SumInsured>10000</SumInsured>
     <Organization>US</Organization>
    </GroupPolicies>
</ListOfClientSumInsuredReportIo>

使用的XSLT:

<?xml version="1.0" encoding="utf-8"?>
   <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="text" indent="yes"/>      
      <xsl:template match="/SiebelMessage/ListOfClientSumInsuredReportIo">
  <xsl:text>&#09;&#09;</xsl:text>
  <xsl:text>Client Sum Insured Report</xsl:text>
  <xsl:text>&#10;</xsl:text>
        <xsl:apply-templates select="GroupPolicies[not(preceding-sibling::GroupPolicies/Organization = Organization)]/Organization" />
  </xsl:template>

  <xsl:template match="GroupPolicies" >
        <xsl:variable name="count" select="position()"/>
        <!--xsl:value-of select="{$count}"/-->
        <xsl:text>&#09;</xsl:text>
        <xsl:value-of select="Policy"/>
        <xsl:text>&#09;</xsl:text>
        <xsl:value-of select="Customer"/>
        <xsl:text>&#09;</xsl:text>
        <xsl:value-of select="Cover"/>
        <xsl:text>&#09;</xsl:text>
        <xsl:value-of select="Addenda"/> <!-- Getting Distinct Count of Addendas while it is not blank-->
        <xsl:text>&#09;</xsl:text>
        <xsl:value-of select="SumInsured"/>
        <xsl:text>&#09;</xsl:text>
        <xsl:value-of select="CommAmt"/>   
        <xsl:text>&#10;</xsl:text>            
  </xsl:template>        

  <xsl:template match="Organization" >
        <xsl:text>&#10;</xsl:text>
        <xsl:text>SNo.</xsl:text>
        <xsl:text>&#09;</xsl:text>
        <xsl:text>Policy Number</xsl:text>
        <xsl:text>&#09;</xsl:text>
        <xsl:text>Customer Name</xsl:text>
        <xsl:text>&#09;</xsl:text>
        <xsl:text>Cover Note #</xsl:text>
        <xsl:text>&#09;</xsl:text>
        <xsl:text>No. of Addendas</xsl:text>
        <xsl:text>&#09;</xsl:text>
        <xsl:text>Sum Insured</xsl:text>
        <xsl:text>&#09;</xsl:text>
        <xsl:text>Total Commission</xsl:text>
        <xsl:text>&#10;</xsl:text>

     <xsl:variable name="temp" select="." />         
     <xsl:apply-templates select="//GroupPolicies[Organization = current()]" />

     </xsl:template>
   </xsl:stylesheet>

感谢您提出任何建议。

1 个答案:

答案 0 :(得分:2)

更改(链接第47行)

<xsl:apply-templates select="//GroupPolicies[Organization = current()]" />

<xsl:apply-templates select="//GroupPolicies[Organization = current() and not(preceding-sibling::GroupPolicies/Cover=Cover)]" />

改变(第21,23,25行)

<xsl:value-of select="Addenda"/>
<xsl:value-of select="SumInsured"/>
<xsl:value-of select="CommAmt"/> 

<xsl:value-of select="count(../GroupPolicies[Organization=current()/Organization and Cover=current()/Cover]/Addenda[string-length()&gt;0])"/>
<xsl:value-of select="sum(../GroupPolicies[Organization=current()/Organization and Cover=current()/Cover]/SumInsured)"/>
<xsl:value-of select="sum(../GroupPolicies[Organization=current()/Organization and Cover=current()/Cover]/CommAmt)"/> 

更改(第13行)

<!--xsl:value-of select="{$count}"/-->

<xsl:value-of select="$count"/>

您需要更多地清理间距/格式,但这会产生您想要的输出所需的内容。

编辑以添加评论中OP提出的其他要求

要将组织添加到表格顶部,只需添加

即可
<xsl:value-of select="."/>

到组织模板的顶部。

要添加每个表总计,请添加以下行

<xsl:value-of select="sum(../../GroupPolicies[Organization=current()]/SumInsured)"/>
<xsl:value-of select="sum(../../GroupPolicies[Organization=current()]/CommAmt)"/>

到组织模板的底部(在apply-templates调用之后),使用适当的间距和回车格式。