2011-11-25 29 views
0

我不確定這是否可能,但我們現在就去。xsl:for-each Split Records

我有一個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 - 或 - CLM或TOTATALS節點然後只處理30個PROV或CLM或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> 

我目前的情況是這樣的分裂不工作&我得到異常:異常在線程「AWT- EventQueue-2「java.lang.OutOfMemoryError:儘管分配-Xms/-Xmx2G內存,Java堆空間。

+0

你的問題似乎有點不清楚。你正在談論採取前30項,但你在你的代碼中使用模運算符。看起來你正試圖把每30個項目(1-30,31-60,61- ..)放在一個表格中。那是對的嗎?是的,你將需要一個嵌套循環。 – grtjn

+0

另外,PROV,CLM和TOTALS是否以混合順序出現?這些應該顯示在單獨的表格中嗎?首先所有那些PROV,然後其他人? – grtjn

+0

@grtjn這是我試圖做的100% - 「把每30個項目(1-30,31-60,61- ..」)。關於嵌套循環,CLM&TOTALS是PROV的子節點 - CLM首先發生然後是TOTALS(CLM&TOTALS也可以在一個PROV節點內多次出現)。爲了評估它們,我必須首先通過PROV - 這就是我使用嵌套循環的方式,我不確定這是否意味着什麼。 – Modumo

回答

1

Kamza,你有一部分是正確的,但你的方法有一些缺陷。你首先在PROV元素上使用for-each,然後在for中爲每個你有一個如果導致輸出只寫入PROV元素1,31,61等等。嵌套for-each循環有類似的問題。只有CLM元素1,31,61,...被寫入,只有TOTALS 1,31,61,...

(實際上,我懷疑在每個PROV中只會有一個TOTALS,這樣在你的代碼)。

此外,從我的理解你的描述和意見是,你試圖一次寫出30行,並開始一個新的表,甚至是一個新的頁面,之後,與另一個30行或剩下的內容。由於沒有行爲PROV元素本身編寫,我認爲它只是關於CLM和TOTALS行,其中30的計數應該包括兩者。

你需要的是一個沿着所有CLM和TOTALS元素的外部for-each循環。您可以使用該表達式爲:

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

然後使用如果你已經有創建一個新的錶行1,31,61,...

爲了與第一代填表格接下來30個項目,您需要向前看30個職位。 PROV元素在這裏有點問題。假設CLM和總計僅在PROV發生,PROV未在其他地方使用,你可以合理安全地使用下面的軸爲:

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

返回30個項目,既CLM和彙總混合,但在文檔順序。您需要兩個額外的,如果公司(或選擇)這兩個,和輸出之間的相應錶行區分:

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

在你的代碼有FO:表體內部的for-each循環中,使每個錶行被包裹在一個新的表體中。這是不必要的。將表體移到內部循環之外。你只需要一個包裝兩行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循環,但它可能是由其他的東西引起的。例如,一張簡單的表格或者一張太大而無法呈現的文檔也可能是原因。上面的代碼應該相當有效。如果它仍然給你帶來麻煩,請嘗試從命令行處理東西,甚至可能使用不同的解析器。

+0

它的工作原理!非常感謝 - 你是一個絕對的天才!我從你的帖子中學到了很多東西 - 非常感謝。 – Modumo

0

HM ..我沒有時間看你的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> 
+0

感謝您的迴應 - 我會實施您的建議並讓您知道它是怎麼回事.. – Modumo

+0

當我運行我的代碼時,我得到錯誤:「節點測試匹配NCName:*或QName預計。 &lt; xsl:template match =「(/&gt;&gt;&lt;'','30',']' 」&'Extra extra illegal token:')','[','position','/PROV | // CLM | // TOTALS)[position()<= 30]">。我應該如何從主模板調用此模板?我正在使用 Modumo

+2

@kamza模板匹配不能像這樣寫,但是你可以用 grtjn

0

您可以修改您的xsl:for-每個語句,把它們限制前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]"/> 
+0

我實施了第一項建議,但仍然耗盡內存。我不知道如何實現第二個建議。我應該命名模板名稱爲?正如你可能已經猜到的那樣,當談到xslt/xsl-fo時,我是一個新手。 – Modumo