for-each分割记录



我不确定这是否可能,但我们开始吧。

有一个xml文件:

<ROOT>
  <MEM-STMT>   
    <COUNTRY>co</COUNTRY>   
    <CURRENCY>cu</CURRENCY>   
    <STMT>   
      <ST-NO>1</ST-NO>   
      <ST-DATE>21-JUL-11</ST-DATE>   
      <CC>21</CC>   
      <YY>11</YY>   
      <MM>07</MM>   
      <DD>21</DD>   
    </STMT>   
    <MEM-DET>   
      <MEM-NO>9</MEM-NO>   
      <MEM-PROD-LEV>24</MEM-PROD-LEV>   
      <MEM-OPTION>option</MEM-OPTION>   
      <MEM-EMP-NO/>   
      <MEM-EMP-NAME>name</MEM-EMP-NAME>   
    </MEM-DET>   
    <MEM-ADDR>   
      <MEM-NAME>name</MEM-NAME>   
      <MEM-ADDR1>                  Addr1</MEM-ADDR1>   
      <MEM-ADDR2>                           Addr2</MEM-ADDR2>   
      <MEM-ADDR3>                         Addr3</MEM-ADDR3>   
      <MEM-SUB>                            Sub</MEM-SUB>   
      <MEM-CITY>                          +2</MEM-CITY>   
      <MEM-REG>                   Employer:reg</MEM-REG>   
      <MEM-CNTRY/>   
      <MEM-PCODE/>   
      <MEM-EMPCODE/>   
    </MEM-ADDR>   
    <ACC>   
      <PROV>   
        <PR-NO>1</PR-NO>   
        <PR-NAME>  pr</PR-NAME>   
        <REF-NO>1</REF-NO>   
        <CLM>   
          <REF>1</REF>   
          <CL-DEP-NO>04</CL-DEP-NO>   
          <CL-DEP-NAME>dep</CL-DEP-NAME>   
          <CL-DOS>10-APR-11</CL-DOS>   
          <CC>21</CC>   
          <YY>11</YY>   
          <MM>04</MM>   
          <DD>10</DD>   
          <CL-TAR-DRUG-CD>1 </CL-TAR-DRUG-CD>   
          <CL-TAR-DRUG-DESC>desc </CL-TAR-DRUG-DESC>   
          <CL-NO>1</CL-NO>   
          <CL-LINE>2</CL-LINE>   
          <CL-AMT>16.8</CL-AMT>   
          <CL-TAR-AMT>16.8</CL-TAR-AMT>   
          <CL-PAID-PROV>16.8</CL-PAID-PROV>   
          <CL-PAID-MEM>0</CL-PAID-MEM>   
          <CL-RSN/>   
        </CLM>   
        <CLM>   
          <REF>1</REF>   
          <CL-DEP-NO>04</CL-DEP-NO>   
          <CL-DEP-NAME>dep </CL-DEP-NAME>   
          <CL-DOS>20-APR-11</CL-DOS>   
          <CC>21</CC>   
          <YY>11</YY>   
          <MM>04</MM>   
          <DD>20</DD>   
          <CL-TAR-DRUG-CD>1 </CL-TAR-DRUG-CD>   
          <CL-TAR-DRUG-DESC>desc </CL-TAR-DRUG-DESC>   
          <CL-NO>1</CL-NO>   
          <CL-LINE>2</CL-LINE>   
          <CL-AMT>50.4</CL-AMT>   
          <CL-TAR-AMT>50.4</CL-TAR-AMT>   
          <CL-PAID-PROV>50.4</CL-PAID-PROV>   
          <CL-PAID-MEM>0</CL-PAID-MEM>   
          <CL-RSN/>   
        </CLM>   
        <TOTALS>   
          <TOT-AMT>67.2</TOT-AMT>   
          <TOT-TAR-AMT>67.2</TOT-TAR-AMT>   
          <TOT-PAID-PROV>67.2</TOT-PAID-PROV>   
          <TOT-PAID-MEM>0</TOT-PAID-MEM>   
        </TOTALS>   
      </PROV>   
      <PROV>   
        <PR-NO>2</PR-NO>   
        <PR-NAME>  pr</PR-NAME>   
        <REF-NO>1</REF-NO>   
        <CLM>   
          <REF>1</REF>   
          <CL-DEP-NO>04</CL-DEP-NO>   
          <CL-DEP-NAME>dep</CL-DEP-NAME>   
          <CL-DOS>10-APR-11</CL-DOS>   
          <CC>21</CC>   
          <YY>11</YY>   
          <MM>04</MM>   
          <DD>10</DD>   
          <CL-TAR-DRUG-CD>1</CL-TAR-DRUG-CD>   
          <CL-TAR-DRUG-DESC>desc </CL-TAR-DRUG-DESC>   
          <CL-NO>1</CL-NO>   
          <CL-LINE>2</CL-LINE>   
          <CL-AMT>15</CL-AMT>   
          <CL-TAR-AMT>0</CL-TAR-AMT>   
          <CL-PAID-PROV>15</CL-PAID-PROV>   
          <CL-PAID-MEM>0</CL-PAID-MEM>   
          <CL-RSN/>   
        </CLM>   
        <TOTALS>   
          <TOT-AMT>15</TOT-AMT>   
          <TOT-TAR-AMT>0</TOT-TAR-AMT>   
          <TOT-PAID-PROV>15</TOT-PAID-PROV>   
          <TOT-PAID-MEM>0</TOT-PAID-MEM>   
        </TOTALS>   
      </PROV>   
      <PROV>   
        <PR-NO>1</PR-NO>   
        <PR-NAME>  pr</PR-NAME>   
        <REF-NO>I0428202</REF-NO>   
        <CLM>   
          <REF>I0428202</REF>   
          <CL-DEP-NO>03</CL-DEP-NO>   
          <CL-DEP-NAME>dep</CL-DEP-NAME>   
          <CL-DOS>10-APR-11</CL-DOS>   
          <CC>21</CC>   
          <YY>11</YY>   
          <MM>04</MM>   
          <DD>10</DD>   
          <CL-TAR-DRUG-CD>2</CL-TAR-DRUG-CD>   
          <CL-TAR-DRUG-DESC>desc</CL-TAR-DRUG-DESC>   
          <CL-NO>112153</CL-NO>   
          <CL-LINE>217615</CL-LINE>   
          <CL-AMT>31.58</CL-AMT>   
          <CL-TAR-AMT>0</CL-TAR-AMT>   
          <CL-PAID-PROV>31.58</CL-PAID-PROV>   
          <CL-PAID-MEM>0</CL-PAID-MEM>   
          <CL-RSN/>   
        </CLM>   
        <TOTALS>   
          <TOT-AMT>31.58</TOT-AMT>   
          <TOT-TAR-AMT>0</TOT-TAR-AMT>   
          <TOT-PAID-PROV>31.58</TOT-PAID-PROV>   
          <TOT-PAID-MEM>0</TOT-PAID-MEM>   
        </TOTALS>   
      </PROV>   
      <PROV>   
        <PR-NO>1</PR-NO>   
        <PR-NAME> pr</PR-NAME>   
        <REF-NO>0027579</REF-NO>   
        <CLM>   
          <REF>1</REF>   
          <CL-DEP-NO>04</CL-DEP-NO>   
          <CL-DEP-NAME>dep</CL-DEP-NAME>   
          <CL-DOS>09-JUN-11</CL-DOS>   
          <CC>21</CC>   
          <YY>11</YY>   
          <MM>06</MM>   
          <DD>09</DD>   
          <CL-TAR-DRUG-CD>99200 </CL-TAR-DRUG-CD>   
          <CL-TAR-DRUG-DESC>desc</CL-TAR-DRUG-DESC>   
          <CL-NO>1</CL-NO>   
          <CL-LINE>1</CL-LINE>   
          <CL-AMT>12</CL-AMT>   
          <CL-TAR-AMT>0</CL-TAR-AMT>   
          <CL-PAID-PROV>12</CL-PAID-PROV>   
          <CL-PAID-MEM>0</CL-PAID-MEM>   
          <CL-RSN/>   
        </CLM>   
        <TOTALS>   
          <TOT-AMT>12</TOT-AMT>   
          <TOT-TAR-AMT>0</TOT-TAR-AMT>   
          <TOT-PAID-PROV>12</TOT-PAID-PROV>   
          <TOT-PAID-MEM>0</TOT-PAID-MEM>   
        </TOTALS>   
      </PROV>   
    </ACC>   
    <RSN-LIST>   
      <RSN-ERR>????</RSN-ERR>   
      <RSN-DESC/>   
    </RSN-LIST>   
    <FIN-OTHER>   
      <FIN-DATE/>   
      <FIN-AMT>0</FIN-AMT>   
      <FIN-TT/>   
    </FIN-OTHER>   
    <GTOTALS>   
      <GTOT-AMT>125.78</GTOT-AMT>   
      <GTOT-TAR-AMT>67.2</GTOT-TAR-AMT>   
      <GTOT-PAID-PROV>125.78</GTOT-PAID-PROV>   
      <GTOT-PAID-MEM>0</GTOT-PAID-MEM>   
    </GTOTALS>   
    <MEM-GTOT>   
      <M-MESSAGE/>   
      <M-TOT-PAID-MEM>0</M-TOT-PAID-MEM>   
      <M-PMT-METH/>   
    </MEM-GTOT>   
    <FIN-BAL>   
      <FIN-BDATE>21-JUL-11</FIN-BDATE>   
      <FIN-BAMT>0</FIN-BAMT>   
      <FIN-BTT/>   
    </FIN-BAL>   
  </MEM-STMT>   
</ROOT> 

,我想使用下面的逻辑拆分从它返回的记录:

如果xml文件有30个或更多的prove -or- clm -or- totalals节点,则只处理30个prove -or- clm -or- totalals节点。如果剩余节点数少于30,则对整个xml文件执行此操作,处理它们以完成转换

我使用下面的xsl来完成:

<xsl:template name="PROVIDER">
<fo:page-sequence master-reference="global">
<fo:flow flow-name="xsl-region-body">
<fo:wrapper font-size="7pt" font-family="Helvetica">
<fo:block-container >
<xsl:variable name="CURRENCYSYMBOL"><xsl:value-of select="ROOT/MEM-STMT/CURRENCY"/></xsl:variable>
<xsl:for-each select="ROOT/MEM-STMT/ACC/PROV">
<xsl:if test="(position() mod 30 = 1)">
<fo:block >
    <fo:table table-layout="fixed" width="190mm" border-style="solid">
    <fo:table-column column-width="22mm"/>
    <fo:table-column column-width="16mm"/>
    <fo:table-column column-width="18mm"/>
    <fo:table-column column-width="39mm"/>
<!--    <fo:table-column column-width="15mm"/>  -->
    <fo:table-column column-width="20mm"/>
    <fo:table-column column-width="20mm"/>
    <fo:table-column column-width="20mm"/>
    <fo:table-column column-width="20mm"/>
    <fo:table-column column-width="15mm"/>
    <fo:table-header border="solid" >
        <fo:table-row  border-style="solid">
        <fo:table-cell  background-color="{$HeaderGray}" number-columns-spanned="9" padding="2pt">
            <fo:block font-size="7pt" text-align="left" font-weight="bold">Provider:
            <xsl:value-of select="PR-NO"/>-
            <xsl:value-of select="PR-NAME"/>
            <xsl:text>&#xA0;  </xsl:text>  Ref No:
            <xsl:value-of select="REF-NO"/>
            </fo:block>
        </fo:table-cell>
        </fo:table-row>
        <fo:table-row border-style="solid">
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Patient</fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Serv Date</fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Tariff/Drug</fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Description</fo:block>
        </fo:table-cell>
    <!--    <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Claim No</fo:block>
        </fo:table-cell>     -->
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Claim Amount</fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Tariff Amount</fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Paid Provider</fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Paid Member</fo:block>
        </fo:table-cell>
        <fo:table-cell border-style="solid" padding="2pt">
            <fo:block text-align="center" font-weight="bold">Reason</fo:block>
        </fo:table-cell>
        </fo:table-row>
    </fo:table-header>
<xsl:for-each select="./CLM">
    <xsl:if test="(position() mod 30 = 1)"> 
    <fo:table-body font-size="7pt">
    <fo:table-row>
        <fo:table-cell padding="2pt" >
            <fo:block>
            <xsl:value-of select="CL-DEP-NAME"/><xsl:text>&#xA0;  </xsl:text>
            <xsl:value-of select="CL-DEP-NO"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt" >
            <fo:block>
            <xsl:value-of select="CL-DOS"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt" >
            <fo:block>
            <xsl:value-of select="CL-TAR-DRUG-CD"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt" >
            <fo:block>
            <xsl:value-of select="CL-TAR-DRUG-DESC"/>
            </fo:block>
        </fo:table-cell>
    <!--    <fo:table-cell padding="2pt">
            <fo:block>
            <xsl:value-of select="CL-NO"/>
            </fo:block>
        </fo:table-cell>  -->
        <fo:table-cell padding="2pt">
            <fo:block text-align="right">
            <xsl:if test="CL-AMT != '0'">
                <xsl:value-of select="$CURRENCYSYMBOL"/>
                <xsl:value-of select="format-number(CL-AMT,'#,##0.00')"/>
            </xsl:if>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt">
            <fo:block text-align="right">
            <xsl:if test="CL-TAR-AMT != '0'">
                <xsl:value-of select="$CURRENCYSYMBOL"/>
                <xsl:value-of select="format-number(CL-TAR-AMT,'#,##0.00')"/>
            </xsl:if>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt" >
            <fo:block text-align="right">
            <xsl:if test="CL-PAID-PROV != '0'">
                <xsl:value-of select="$CURRENCYSYMBOL"/>
                <xsl:value-of select="format-number(CL-PAID-PROV,'#,##0.00')"/>
            </xsl:if>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt">
            <fo:block text-align="right">
            <xsl:if test="CL-PAID-MEM != '0'">
                <xsl:value-of select="$CURRENCYSYMBOL"/>
                <xsl:value-of select="format-number(CL-PAID-MEM,'#,##0.00')"/>
            </xsl:if>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt">
            <fo:block text-align="right">
                <xsl:if test="CL-RSN != '????'">
                    <xsl:value-of select="CL-RSN"/>
                </xsl:if>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
    </fo:table-body>
    </xsl:if>
    </xsl:for-each>
    <xsl:for-each select="./TOTALS">
    <xsl:if test="(position() mod 30 = 1)">
    <fo:table-body font-size="7pt">
    <fo:table-row border-style="solid">
        <fo:table-cell padding="2pt" number-columns-spanned="4" >
            <fo:block >Totals for Invoice</fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt" >
            <fo:block text-align="right">
        <!--    <xsl:if test="TOT-AMT != '0'">       -->
                <xsl:value-of select="$CURRENCYSYMBOL"/>
                <xsl:value-of select="format-number(TOT-AMT,'#,##0.00')"/>
        <!--    </xsl:if>     -->
            </fo:block>
        </fo:table-cell >
        <fo:table-cell padding="2pt">
            <fo:block text-align="right">
        <!--    <xsl:if test="TOT-TAR-AMT != '0'">  -->
                <xsl:value-of select="$CURRENCYSYMBOL"/>
                <xsl:value-of select="format-number(TOT-TAR-AMT,'#,##0.00')"/>
        <!--    </xsl:if>    -->
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt">
            <fo:block text-align="right">
        <!--    <xsl:if test="TOT-PAID-PROV != '0'">    -->
                <xsl:value-of select="$CURRENCYSYMBOL"/>
                <xsl:value-of select="format-number(TOT-PAID-PROV,'#,##0.00')"/>
        <!--    </xsl:if>    -->
            </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2pt">
            <fo:block text-align="right">
        <!--    <xsl:if test="TOT-PAID-MEM != '0'">   -->
                <xsl:value-of select="$CURRENCYSYMBOL"/>
                <xsl:value-of select="format-number(TOT-PAID-MEM,'#,##0.00')"/>
        <!--    </xsl:if>   -->
            </fo:block>
        </fo:table-cell>
        <fo:table-cell >
            <fo:block>
            </fo:block>
        </fo:table-cell>
    </fo:table-row>
    </fo:table-body>
    </xsl:if>
    </xsl:for-each>
    </fo:table>
</fo:block>
</xsl:if>
</xsl:for-each>
</fo:block-container>
</fo:wrapper>
</fo:flow>
</fo:page-sequence>

我当前的场景是这样的分割不起作用&异常在线程"AWT-EventQueue-2" Java .lang. outofmemoryerror: Java堆空间尽管分配-Xms/-Xmx2G内存。

Kamza,你有一部分是对的,但是你的方法有一些缺陷。首先在PROV元素上使用for-each语句,在for-each语句中使用if语句,使输出仅针对PROV元素1、31、61等进行编写。嵌套的for-each循环也有类似的问题。只有CLM元素1,31,61,…

(实际上,我怀疑在每个PROV中只会有一个TOTALS,因此在您的代码中可以。)

此外,从我从你的描述和评论中理解的是,你试图一次写出30行,并在那之后开始一个新的表,甚至一个新的页面,还有另外30行,或者剩下的。因为没有为PROV元素本身写入行,所以我假设它只是关于CLM和TOTALS行,其中计数30应该包括这两行。

您需要的是一个外部的for-each循环,它遍历所有CLM和TOTALS元素。你可以使用这个表达式:

    <xsl:for-each select="ROOT/MEM-STMT/ACC/PROV/*[self::CLM or self::TOTALS]">

如果你已经创建了一个新的表,第1,31,61,…

要用前30项填充表,您需要向前查找30个位置。在这里,PROV元素有点问题。假设CLM和TOTALS只出现在PROV中,并且PROV没有在其他地方使用,那么您可以合理安全地使用以下轴:

    <xsl:for-each select="(following::*[self::CLM or self::TOTALS])[30 >= position()]">

返回30项,CLM和TOTALS混合在一起,但按文档顺序排列。您需要两个额外的if(或一个选择)来区分这两者,并输出适当的表行:

    <xsl:if test="self::CLM">
        ...
    </xsl:if>
    <xsl:if test="self::TOTALS">
        ...
    </xsl:if>

在您的代码中,您必须在内部for-each循环中使用:table-body,导致每个表行都被包装在一个新的表体中。这是不必要的。将表体移动到内循环的外部。您只需要对CLM和TOTALS行进行一次包装。

最后,为每30个项目编写一个新表。我认为你也需要重新开始一个页面序列。这将导致每个表显示在单独的页面上。把这些放在一起,您会得到一个类似于这样的XSLT:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:variable name="HeaderGray" select="'gray'"/>
    <xsl:template match="/">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="global">
                    <fo:region-body/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <xsl:apply-templates select="/" mode="PROVIDER"/>
        </fo:root>
    </xsl:template>
    <xsl:template match="/" mode="PROVIDER">
        <xsl:variable name="CURRENCYSYMBOL" select="string(ROOT/MEM-STMT/CURRENCY)"/>
        <xsl:for-each select="ROOT/MEM-STMT/ACC/PROV/*[self::CLM or self::TOTALS]">
            <xsl:if test="position() mod 30 = 1">
                <fo:page-sequence master-reference="global">
                    <fo:flow flow-name="xsl-region-body">
                        <fo:wrapper font-size="7pt" font-family="Helvetica">
                            <fo:block-container>
                                <fo:block>
                                    <fo:table table-layout="fixed" width="190mm"
                                        border-style="solid">
                                        <fo:table-column column-width="22mm"/>
                                        <fo:table-column column-width="16mm"/>
                                        <fo:table-column column-width="18mm"/>
                                        <fo:table-column column-width="39mm"/>
                                        <!--    <fo:table-column column-width="15mm"/>  -->
                                        <fo:table-column column-width="20mm"/>
                                        <fo:table-column column-width="20mm"/>
                                        <fo:table-column column-width="20mm"/>
                                        <fo:table-column column-width="20mm"/>
                                        <fo:table-column column-width="15mm"/>
                                        <fo:table-header border="solid">
                                            <fo:table-row border-style="solid">
                                                <fo:table-cell background-color="{$HeaderGray}"
                                                  number-columns-spanned="9" padding="2pt">
                                                  <fo:block font-size="7pt" text-align="left"
                                                  font-weight="bold">Provider: <xsl:value-of
                                                  select="PR-NO"/>- <xsl:value-of select="PR-NAME"/>
                                                  <xsl:text>&#xA0;  </xsl:text> Ref No:
                                                  <xsl:value-of select="REF-NO"/>
                                                  </fo:block>
                                                </fo:table-cell>
                                            </fo:table-row>
                                            <fo:table-row border-style="solid">
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Patient</fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Serv Date</fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Tariff/Drug</fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Description</fo:block>
                                                </fo:table-cell>
                                                <!--    <fo:table-cell border-style="solid" padding="2pt"> 
            <fo:block text-align="center" font-weight="bold">Claim No</fo:block> 
        </fo:table-cell>     -->
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Claim Amount</fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Tariff Amount</fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Paid Provider</fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Paid Member</fo:block>
                                                </fo:table-cell>
                                                <fo:table-cell border-style="solid" padding="2pt">
                                                  <fo:block text-align="center" font-weight="bold"
                                                  >Reason</fo:block>
                                                </fo:table-cell>
                                            </fo:table-row>
                                        </fo:table-header>
                                        <fo:table-body font-size="7pt">
                                            <xsl:for-each
                                            select="(following::*[self::CLM or self::TOTALS])[30 >= position()]">
                                            <xsl:if test="self::CLM">
                                                  <fo:table-row>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block>
                                                  <xsl:value-of select="CL-DEP-NAME"/>
                                                  <xsl:text>&#xA0;  </xsl:text>
                                                  <xsl:value-of select="CL-DEP-NO"/>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block>
                                                  <xsl:value-of select="CL-DOS"/>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block>
                                                  <xsl:value-of select="CL-TAR-DRUG-CD"/>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block>
                                                  <xsl:value-of select="CL-TAR-DRUG-DESC"/>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <!--    <fo:table-cell padding="2pt"> 
            <fo:block> 
            <xsl:value-of select="CL-NO"/> 
            </fo:block> 
        </fo:table-cell>  -->
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <xsl:if test="CL-AMT != '0'">
                                                  <xsl:value-of select="$CURRENCYSYMBOL"/>
                                                  <xsl:value-of
                                                  select="format-number(CL-AMT,'#,##0.00')"/>
                                                  </xsl:if>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <xsl:if test="CL-TAR-AMT != '0'">
                                                  <xsl:value-of select="$CURRENCYSYMBOL"/>
                                                  <xsl:value-of
                                                  select="format-number(CL-TAR-AMT,'#,##0.00')"/>
                                                  </xsl:if>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <xsl:if test="CL-PAID-PROV != '0'">
                                                  <xsl:value-of select="$CURRENCYSYMBOL"/>
                                                  <xsl:value-of
                                                  select="format-number(CL-PAID-PROV,'#,##0.00')"/>
                                                  </xsl:if>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <xsl:if test="CL-PAID-MEM != '0'">
                                                  <xsl:value-of select="$CURRENCYSYMBOL"/>
                                                  <xsl:value-of
                                                  select="format-number(CL-PAID-MEM,'#,##0.00')"/>
                                                  </xsl:if>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <xsl:if test="CL-RSN != '????'">
                                                  <xsl:value-of select="CL-RSN"/>
                                                  </xsl:if>
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  </fo:table-row>
                                            </xsl:if>
                                            <xsl:if test="self::TOTALS">
                                                  <fo:table-row border-style="solid">
                                                  <fo:table-cell padding="2pt"
                                                  number-columns-spanned="4">
                                                  <fo:block>Totals for Invoice</fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <!--    <xsl:if test="TOT-AMT != '0'">       -->
                                                  <xsl:value-of select="$CURRENCYSYMBOL"/>
                                                  <xsl:value-of
                                                  select="format-number(TOT-AMT,'#,##0.00')"/>
                                                  <!--    </xsl:if>     -->
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <!--    <xsl:if test="TOT-TAR-AMT != '0'">  -->
                                                  <xsl:value-of select="$CURRENCYSYMBOL"/>
                                                  <xsl:value-of
                                                  select="format-number(TOT-TAR-AMT,'#,##0.00')"/>
                                                  <!--    </xsl:if>    -->
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <!--    <xsl:if test="TOT-PAID-PROV != '0'">    -->
                                                  <xsl:value-of select="$CURRENCYSYMBOL"/>
                                                  <xsl:value-of
                                                  select="format-number(TOT-PAID-PROV,'#,##0.00')"/>
                                                  <!--    </xsl:if>    -->
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell padding="2pt">
                                                  <fo:block text-align="right">
                                                  <!--    <xsl:if test="TOT-PAID-MEM != '0'">   -->
                                                  <xsl:value-of select="$CURRENCYSYMBOL"/>
                                                  <xsl:value-of
                                                  select="format-number(TOT-PAID-MEM,'#,##0.00')"/>
                                                  <!--    </xsl:if>   -->
                                                  </fo:block>
                                                  </fo:table-cell>
                                                  <fo:table-cell>
                                                  <fo:block> </fo:block>
                                                  </fo:table-cell>
                                                  </fo:table-row>
                                            </xsl:if>
                                        </xsl:for-each>
                                        </fo:table-body>
                                    </fo:table>
                                </fo:block>
                            </fo:block-container>
                        </fo:wrapper>
                    </fo:flow>
                </fo:page-sequence>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

注意:我不完全相信这会阻止你得到一个异常。你给人的印象是这是因为你的for-each循环,但它可能是由其他原因引起的。例如,表太大或者文档太大而无法呈现也可能是原因。上面的代码应该相当高效。如果它仍然给您带来麻烦,请尝试从命令行处理,甚至可能使用不同的解析器。

…我没有时间详细查看xslt,但是您的逻辑应该可以使用如下内容:

<xsl:template match="(//PROV | //CLM | //TOTALS)[position() <= 30]">
   <xsl:if test="local-name() = 'PROV'">
       <!-- do stuff with PROV node -->
   </xsl:if>
   <xsl:if test="local-name() = 'CLM'">
       <!-- do stuff with CLM node -->
   </xsl:if>
   <xsl:if test="local-name() = 'TOTALS'">
       <!-- do stuff with TOTALS node -->
   </xsl:if>
</xsl:template>

您可以修改xsl:for-each语句,将它们限制为前30个条目:

<xsl:for-each select="ROOT/MEM-STMT/ACC/PROV[position()&lt;=30]">

或者您可以将xsl:for-each逻辑提取到模板中,然后只选择前30个来应用模板:

<xsl:apply-templates select="ROOT/MEM-STMT/ACC/PROV[position()&lt;=30]"/>

最新更新