xsl:for-each Split Records

时间:2011-11-25 13:53:22

标签: xslt xsl-fo xslt-1.0

我不确定这是否可能,但我们走了。

我有一个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个或更多PROV-or-CLM-or-TOTATALS节点,则只处理30个PROV-or-CLM-or-TOTATALS节点。如果剩余节点数小于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>

我目前的情况是分裂不起作用&amp;我得到异常:线程“AWT-EventQueue-2”中的异常java.lang.OutOfMemoryError:Java堆空间尽管分配了-Xms / -Xmx2G内存。

3 个答案:

答案 0 :(得分:1)

Kamza,你有一部分是正确的,但你的方法有一些缺陷。你从PROV元素的for-each开始,并且在for-each中你有一个if,导致只为PROV元素1,31,61等写入输出。嵌套的for-each循环有类似的问题。仅写入CLM元素1,31,61,..,仅像TOTALS 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>

在你的代码中,你有fo:table-body在内部for-each循环中,导致每个table-row被包装在一个新的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循环,但它可能是由其他东西引起的。例如,一个简单到大的表,或者太大而无法渲染的文档也可能是原因。上面的代码应该相当有效。如果它仍然给你带来麻烦,请尝试从命令行处理事情,甚至可能使用不同的解析器。

答案 1 :(得分:0)

嗯..我没有时间详细查看你的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>

答案 2 :(得分:0)

您可以修改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]"/>
相关问题