XSLT分页显示一些计算出的节点值以及在下一行(II)上检索到的上一行值

时间:2019-03-30 13:10:17

标签: javascript xml xslt

再次检查与上一个请求链接的另一个请求,该请求通过以下stackoverflow链接进行描述:

XSLT get some calculated node value over next line node's value

我不会重复整个问题的详细信息,因为可以检查出来 通过提到的链接。  此第二个新请求也基于提供的维护共享账单列表.xml文件,并且需要显示相同的数据但要分页(分页)。  假设我在该.xml文件中有几十行,自然应该对它进行一些分页,以实现良好,整洁和有效的显示。  为了做到这一点,我只使用了michael.hor257k的解决方案来显示数据,而另一个人使用了分页解决方案。  在提供的.xsl文件中,我确实组装了这两种方法。但是..没用!  个别情况下,他们工作顺利,但是将整个过程放在一起会失败...   接下来,我将同时提供我的.xml文件和相关的.xsl文件以及一些小的.js文件(有助于正确分页),我要你们支持我,因为我无法提出建议。解。  我知道这有点复杂...但这就是我需要显示的内容  再次非常感谢您……非常抱歉无法自己整理一下内容。

1。 xml文件

<?xml version="1.0" encoding="utf-8"?>
  <upkeepList> 
  <upkShare month_year="11_16-12_16" post_dte="01-20-17" due="02-04-17">
  <OpngBlnce>22</OpngBlnce>
  <mnthCrrntAmnt>77</mnthCrrntAmnt> 
   <Rcpt dte="01-26-17" No="5725">
    <amnt>22</amnt>
    <descrpt>"11/16" upkeep </descrpt>
   </Rcpt>
   <Rcpt dte="01-26-17" No="5726">
    <amnt>41</amnt>
    <descrpt>"12/16" upkeep </descrpt>
   </Rcpt>
  </upkShare>

  <upkShare month_year="01_17-02_17" post_dte="03-17-17" due="04-03-17">
   <OpngBlnce/> 
   <mnthCrrntAmnt>74</mnthCrrntAmnt>
   <Rcpt dte="03-30-17" No="5783">
    <amnt>50</amnt>
    <descrpt>"01/17-02/17" upkeep</descrpt>
    </Rcpt>
  </upkShare>

  <upkShare month_year="03-17" post_dte="04-16-17" due="05-02-17"> 
  <OpngBlnce/>
  <mnthCrrntAmnt>55</mnthCrrntAmnt>
  <Rcpt dte="05-10-17" No="5815">
   <amnt>40</amnt>
   <descrpt>"03/17-04/17" upkeep 1</descrpt>
  </Rcpt>
  <Rcpt dte="05-15-17" No="5825">
   <amnt>9</amnt>
   <descrpt>"03/17-04/17" upkeep 2</descrpt>
  </Rcpt> 
 </upkShare>

 <upkShare month_year="04_17-05_17" post_dte="06-05-17" due="06-30-17">
  <OpngBlnce/>
  <mnthCrrntAmnt>64</mnthCrrntAmnt>
  <Rcpt dte="06-14-17" No="5858">
   <amnt>37</amnt>
    <descrpt>"05/17" upkeep 1</descrpt>
  </Rcpt>
  <Rcpt dte="06-18-17" No="5863">
   <amnt>21</amnt>
   <descrpt>"05/17" upkeep 2</descrpt>
  </Rcpt>
 </upkShare>

 <upkShare month_year="06_17" post_dte="07-16-17" due="07-30-17">
  <OpngBlnce/>
  <mnthCrrntAmnt>45</mnthCrrntAmnt>
  <Rcpt dte="07-28-17" No="5948">
   <amnt>38</amnt>
   <descrpt>"06/17" upkeep</descrpt>
  </Rcpt>
 </upkShare> 

  <upkShare month_year="07_17" post_dte="08-16-17" due="08-31-17">
  <OpngBlnce/>
  <mnthCrrntAmnt>54</mnthCrrntAmnt>
  <Rcpt dte="07-28-17" No="6002">
   <amnt>33</amnt>
   <descrpt>"07/17" upkeep 1</descrpt>
  </Rcpt>
  <Rcpt dte="08-02-17" No="6017">
   <amnt>12</amnt>
   <descrpt>"07/17" upkeep 2</descrpt>
  </Rcpt>
 </upkShare>

 <upkShare month_year="08_17" post_dte="09-19-17" due="09-31-17">
  <OpngBlnce></OpngBlnce>
  <mnthCrrntAmnt>41</mnthCrrntAmnt>
  <Rcpt dte="09-29-17" No="6026">
   <amnt>41</amnt>
   <descrpt>"08/17" upkeep </descrpt>
  </Rcpt>
 </upkShare>

 <upkShare month_year="09_17" post_dte="10-16-17" due="10-31-17">
  <OpngBlnce/>
  <mnthCrrntAmnt>34</mnthCrrntAmnt>
  <Rcpt dte="10-26-17" No="6050" >
   <amnt>34</amnt>
   <descrpt>"09/17" upkeep </descrpt>
  </Rcpt>
 </upkShare>

 <upkShare month_year="10_17" post_dte="11-18-17" due="11-31-17">
  <OpngBlnce></OpngBlnce>
  <mnthCrrntAmnt>47</mnthCrrntAmnt>
  <Rcpt dte="11-27-17" No="6052">
   <amnt>10</amnt>
   <descrpt>upkeep amount 1</descrpt>
  </Rcpt>
  <Rcpt dte="11-28-17" No="6084">
   <amnt>8</amnt>
   <descrpt>upkeep amount 2</descrpt>
  </Rcpt>
  <Rcpt dte="11-30-17" No="6104">
   <amnt>27</amnt>
   <descrpt>upkeep amount 3</descrpt>
  </Rcpt>
 </upkShare>

 <upkShare month_year="11_17" post_dte="12-15-17" due="01-07-18">
  <OpngBlnce></OpngBlnce>
  <mnthCrrntAmnt>8</mnthCrrntAmnt>
  <Rcpt dte="01-06-18" No="6135">
   <amnt>17</amnt>
   <descrpt>some upkeep amount</descrpt>
  </Rcpt>
  </upkShare>
 </upkeepList>

2.xsl文件:

 <?xml version="1.0" encoding="UTF-8" ?>
 <xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
  <xsl:strip-space elements="*"/> <xsl:decimal-format name="coerce" NaN="0" />
  <xsl:variable name="upkshr">  <!-- upkshr varbl -->
    <xsl:for-each select="upkShare">  
  <upkp pstdte="{@post_dte}" rltedmnthyr = "{@month_year}"  ob = "{format-number(OpngBlnce, '#', 'coerce')}"
  mcamnt = "{format-number(mnthCrrntAmnt, '#','coerce')}" term = "{@due}" rcptsum = "{format-number(sum(Rcpt/amnt), '#','coerce')}" /> <!-- missing ob node's value forced to zero -->
  </xsl:for-each> 
 </xsl:variable> 
 <xsl:param name="size" select="4"/>
 <xsl:template match="upkeepList">

<html> 
 <head>  
   <script type="text/javascript" src="../js/scrpt_pagn.js"></script> 
   <h3 style="margin-left:45">Upkeep share bills list</h3>
 </head> 
 <body onload="onInitialize()">
 <xsl:apply-templates select="$upkshr[position() mod $size = 1]">
   <xsl:with-param name="pages" select="ceiling(count($upkshr) div $size)"/>
  </xsl:apply-templates>
  </body>
  </html>
 </xsl:template>
 <xsl:template match="$upkshr"> <xsl:param name="pages"/>
   <xsl:variable name="page" select="position()"/>

  <table border="1" id='content{$page}' width="300" height="170" style="text-align:center;margin-left:50; margin-top:22px; display:none">
    <tr bgcolor="#9acd32">
     <th>UpkpShare_Prd</th> <th>PostDate</th> <th>InitBalance</th> 
     <th>UpkpShare_Amount</th>
     <th>DueDate</th> <th>FullAmnt</th> <th>FullAmntPayed</th> 
     <th>AmntDue</th>
    </tr>

    <xsl:for-each select="self::$upkshr | following-sibling::$upkshr[position()&lt;$size]"> 
     <xsl:for-each select="exsl:node-set($upkshr)/upkp"> 
      <tr>
       <td> <xsl:value-of select="@rltedmnthyr"/> </td> <!-- relatd mnthly year -->
       <td> <xsl:value-of select="@pstdte"/> </td> <!-- post date -->
   <xsl:variable name="initblnc" select="sum(preceding-sibling::upkp/@ob) + sum(preceding-sibling::upkp/@mcamnt) - sum(preceding-sibling::upkp/@rcptsum) + @ob" /> 
       <td> <xsl:value-of select="$initblnc"/> <!-- initblnc = initial balance / opening balance -->
       </td>
       <td> <xsl:value-of select="@mcamnt"/> </td> <!-- monthly upkeep share amount -->
      <td> <xsl:value-of select="@term"/> </div> </td>  <!-- due -->
      <td> <xsl:value-of select="$initblnc + @mcamnt"/> </td>  <!-- full amount  -->
      <td> <xsl:value-of select="@rcptsum"/> </td>   <!-- full amount payed -->
      <td> <xsl:value-of select="$initblnc + @mcamnt - @rcptsum"/> </td>  <!-- amount due / closing balance -->
     </tr>
    </xsl:for-each>
   </xsl:for-each>
  <tr>
   <td colspan="8"> 
    <xsl:choose>
     <xsl:when test="$page = 1">
     <xsl:text>pag</xsl:text> <xsl:text> </xsl:text>
     <xsl:value-of select="$page"/>
     <xsl:value-of select="'/'"/>      
     <xsl:value-of select="$pages"/>      
     <xsl:value-of select="' '"/>
     <a href="#{$page+1}" onclick="nextPage({$page+1})">&gt;</a>
    </xsl:when>
    <xsl:when test="$page = $pages">
    <xsl:value-of select="' '"/>
     <a href="#{$page - 1}" onclick="prevPage({$page - 1})">&lt;</a>      
    <xsl:text> </xsl:text> <xsl:text>pag</xsl:text>  
    <xsl:value-of select="' '"/> 
    <xsl:value-of select="$page"/>
    <xsl:value-of select="'/'"/>  
    <xsl:value-of select="$pages"/>
    </xsl:when>
    <xsl:otherwise>
    <a href="#{$page - 1}" onclick="prevPage({$page - 1})">&lt;</a>
    <xsl:text> </xsl:text> <xsl:text>pag</xsl:text>
    <xsl:value-of select="' '"/>      
    <xsl:value-of select="$page"/>      
    <xsl:value-of select="'/'"/> 
    <xsl:value-of select="$pages"/>
    <xsl:value-of select="' '"/>
     <a href="#{$page+1}" onclick="nextPage({$page+1})">&gt;</a>
    </xsl:otherwise>
   </xsl:choose>
   </td> </tr> 
   </table>   
  </xsl:template>
 </xsl:stylesheet>

..最后是.js文件:

function onInitialize()
{
 var i = 1;
  document.getElementById("content"+i).style.display="" ; 
}

function nextPage(num)
{
 document.getElementById("content"+num).style.display="";
 num--;
 document.getElementById("content"+num).style.display="none"; 
}

function prevPage(num)
{
 document.getElementById("content"+num).style.display="";
 num++;
 document.getElementById("content"+num).style.display="none";
}

就是这样。  再次,你们,帮我解决这个(相对困难)的问题!  非常非常感谢您!

1 个答案:

答案 0 :(得分:0)

我不确定我是否已经了解了要创建的HTML,但是以下内容为您的输入生成了三个“页面” /表:

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
  <xsl:strip-space elements="*"/> <xsl:decimal-format name="coerce" NaN="0" />
  <xsl:variable name="upkshr">  <!-- upkshr varbl -->
    <xsl:for-each select="*/upkShare">  
  <upkp pstdte="{@post_dte}" rltedmnthyr = "{@month_year}"  ob = "{format-number(OpngBlnce, '#', 'coerce')}"
  mcamnt = "{format-number(mnthCrrntAmnt, '#','coerce')}" term = "{@due}" rcptsum = "{format-number(sum(Rcpt/amnt), '#','coerce')}" /> <!-- missing ob node's value forced to zero -->
  </xsl:for-each> 
 </xsl:variable> 

 <xsl:variable name="upkp-set" select="exsl:node-set($upkshr)/upkp"/>

 <xsl:param name="size" select="4"/>

 <xsl:output method="html" version="5.0" doctype-system="about:legacy-doctype"/>
 <xsl:template match="upkeepList">

<html> 
 <head>  
   <script type="text/javascript">
function onInitialize()
{
 var i = 1;
  document.getElementById("content"+i).style.display="" ; 
}

function nextPage(num)
{
 document.getElementById("content"+num).style.display="";
 num--;
 document.getElementById("content"+num).style.display="none"; 
}

function prevPage(num)
{
 document.getElementById("content"+num).style.display="";
 num++;
 document.getElementById("content"+num).style.display="none";
}
   </script> 
   <h3 style="margin-left:45">Upkeep share bills list</h3>
 </head> 
 <body onload="onInitialize()">
 <xsl:apply-templates select="$upkp-set[position() mod $size = 1]">
   <xsl:with-param name="pages" select="ceiling(count($upkp-set) div $size)"/>
  </xsl:apply-templates>
  </body>
  </html>
 </xsl:template>
 <xsl:template match="upkp"> <xsl:param name="pages"/>
   <xsl:variable name="page" select="position()"/>

  <table border="1" id='content{$page}' width="300" height="170" style="text-align:center;margin-left:50; margin-top:22px; display:none">
    <tr bgcolor="#9acd32">
     <th>UpkpShare_Prd</th> <th>PostDate</th> <th>InitBalance</th> 
     <th>UpkpShare_Amount</th>
     <th>DueDate</th> <th>FullAmnt</th> <th>FullAmntPayed</th> 
     <th>AmntDue</th>
    </tr>

    <xsl:for-each select=". | following-sibling::upkp[position()&lt;$size]"> 
      <tr>
       <td> <xsl:value-of select="@rltedmnthyr"/> </td> <!-- relatd mnthly year -->
       <td> <xsl:value-of select="@pstdte"/> </td> <!-- post date -->
   <xsl:variable name="initblnc" select="sum(preceding-sibling::upkp/@ob) + sum(preceding-sibling::upkp/@mcamnt) - sum(preceding-sibling::upkp/@rcptsum) + @ob" /> 
       <td> <xsl:value-of select="$initblnc"/> <!-- initblnc = initial balance / opening balance -->
       </td>
       <td> <xsl:value-of select="@mcamnt"/> </td> <!-- monthly upkeep share amount -->
      <td> <xsl:value-of select="@term"/>  </td>  <!-- due -->
      <td> <xsl:value-of select="$initblnc + @mcamnt"/> </td>  <!-- full amount  -->
      <td> <xsl:value-of select="@rcptsum"/> </td>   <!-- full amount payed -->
      <td> <xsl:value-of select="$initblnc + @mcamnt - @rcptsum"/> </td>  <!-- amount due / closing balance -->
     </tr>
    </xsl:for-each>
  <tr>
   <td colspan="8"> 
    <xsl:choose>
     <xsl:when test="$page = 1">
     <xsl:text>pag</xsl:text> <xsl:text> </xsl:text>
     <xsl:value-of select="$page"/>
     <xsl:value-of select="'/'"/>      
     <xsl:value-of select="$pages"/>      
     <xsl:value-of select="' '"/>
     <a href="#{$page+1}" onclick="nextPage({$page+1})">&gt;</a>
    </xsl:when>
    <xsl:when test="$page = $pages">
    <xsl:value-of select="' '"/>
     <a href="#{$page - 1}" onclick="prevPage({$page - 1})">&lt;</a>      
    <xsl:text> </xsl:text> <xsl:text>pag</xsl:text>  
    <xsl:value-of select="' '"/> 
    <xsl:value-of select="$page"/>
    <xsl:value-of select="'/'"/>  
    <xsl:value-of select="$pages"/>
    </xsl:when>
    <xsl:otherwise>
    <a href="#{$page - 1}" onclick="prevPage({$page - 1})">&lt;</a>
    <xsl:text> </xsl:text> <xsl:text>pag</xsl:text>
    <xsl:value-of select="' '"/>      
    <xsl:value-of select="$page"/>      
    <xsl:value-of select="'/'"/> 
    <xsl:value-of select="$pages"/>
    <xsl:value-of select="' '"/>
     <a href="#{$page+1}" onclick="nextPage({$page+1})">&gt;</a>
    </xsl:otherwise>
   </xsl:choose>
   </td> </tr> 
   </table>   
  </xsl:template>
 </xsl:stylesheet>

https://xsltfiddle.liberty-development.net/ncdD7mp

为完整起见,我已内联Javascript代码,但将其保存在单独的文件中当然不会有任何作用。