<xsl:if test="Item[last() &gt 9]">
for(int i=1;i<=(last()-9)/5;i++){
<tr>
<xsl:for-each select="Item[position() &gt;=5+5*i and position() &lt;=9+5*i]">
<td width="15%" abbr="center">
<xsl:value-of select="Value"/>
</td>
</xsl:for-each>
</tr>
}
</xsl:if>更改成
<xsl:if test="Item[last() &gt 9]">
<xsl:for-each select="Item[position() &gt;=1 and position() &lt;=<=(last()-9)/5]">
<tr>
<xsl:for-each select="Item[position() &gt;=5+5*i and position() &lt;=9+5*i]">
<td width="15%" abbr="center">
<xsl:value-of select="Value"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:if>
这样可以嘛,说实话我对XSL知道的很少.

解决方案 »

  1.   

    我晕,你所有的记录都用Item来做标记吗?
    你应该使用数据库里相应的字段做标记,就没有这个烦恼了!
      

  2.   

    我晕,你所有的记录都用Item来做标记吗?
    你应该使用数据库里相应的字段做标记,就没有这个烦恼了!
      

  3.   

    偶也下班了,明天再来!可能会用到choose结构!
      

  4.   

    sgdb(神天月晓):老大,schema不是我定义的,我还郁闷呢
    多帮看看啊study_body(珍惜每一天):
    5+5*i===》i从何而来呀?knight_qmh(辉):有劳了
      

  5.   

    用递归吧!在xsl里用for循环好象不可以吧!只有for-each结构,所以用递归可以解决!
      

  6.   

    xml原文档:<?xml version = "1.0" encoding = "UTF-8"?>
    <form>    
    <item>1</item>    
    <item>2</item>    
    <item>3</item>    
    <item>4</item>    
    <item>5</item>    
    <item>6</item>    
    <item>7</item>    
    <item>8</item>    
    <item>9</item>    
    <item>10</item>    
    <item>11</item>    
    <item>12</item>    
    <item>13</item>    
    <item>14</item>    
    <item>15</item>    
    <item>16</item>    
    <item>17</item>    
    <item>18</item>    
    <item>19</item>    
    <item>20</item>    
    <item>21</item>    
    <item>22</item>    
    <item>23</item>    
    <item>24</item>    
    <item>25</item>
    <item>26</item>
    </form>xsl:<?xml version = "1.0" encoding = "UTF-8"?>
    <xsl:transform xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0">
    <xsl:template match = "/form">
    <xsl:variable name = "countitem" select = "count(./item)"/>
    <xsl:element name = "table">
    <xsl:call-template name = "output_item">
    <xsl:with-param name = "item_counts" select = "count(./item)"/>
    <xsl:with-param name = "item_point" select = "1"/>
    </xsl:call-template>
    </xsl:element>
    </xsl:template>
    <xsl:template name = "output_item">
    <xsl:param name = "item_counts"/>
    <xsl:param name = "item_point"/>
    <xsl:if test = "$item_point &lt;= $item_counts">
    <xsl:element name = "tr">
    <xsl:for-each select = "/form/item[position() >=$item_point and position() &lt;= $item_point + 4]">
    <xsl:element name = "td">
    <xsl:value-of select = "./"/>
    </xsl:element>
    </xsl:for-each>
    </xsl:element>
    <xsl:call-template name = "output_item">
    <xsl:with-param name = "item_counts" select = "$item_counts"/>
    <xsl:with-param name = "item_point" select = "$item_point + 5"/>
    </xsl:call-template>
    </xsl:if>
    </xsl:template>
    </xsl:transform>输出:
    <?xml version = "1.0" encoding = "UTF-8"?>
    <table>
    <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
    <td>4</td>
    <td>5</td>
    </tr>
    <tr>
    <td>6</td>
    <td>7</td>
    <td>8</td>
    <td>9</td>
    <td>10</td>
    </tr>
    <tr>
    <td>11</td>
    <td>12</td>
    <td>13</td>
    <td>14</td>
    <td>15</td>
    </tr>
    <tr>
    <td>16</td>
    <td>17</td>
    <td>18</td>
    <td>19</td>
    <td>20</td>
    </tr>
    <tr>
    <td>21</td>
    <td>22</td>
    <td>23</td>
    <td>24</td>
    <td>25</td>
    </tr>
    <tr>
    <td>26</td>
    </tr>
    </table>
    方法就是递归!
      

  7.   

    上面的递归还是有点问题<?xml version = "1.0" encoding = "UTF-8"?>
    <xsl:transform xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0">
    <xsl:template match = "jilu">
    <xsl:variable name = "countitem" select = "count(item)"/>
    <xsl:element name = "table">
    <xsl:call-template name = "output_item">
    <xsl:with-param name = "item_counts" select = "count(item)"/>
    <xsl:with-param name = "item_point" select = "1"/>
    </xsl:call-template>
    </xsl:element>
    </xsl:template>
    <xsl:template name = "output_item">
    <xsl:param name = "item_counts"/>
    <xsl:param name = "item_point"/>
    <xsl:if test = "$item_point &lt;= $item_counts">
    <xsl:element name = "tr"> <xsl:element name = "td">
    <xsl:value-of select = "item[position() &gt;= $item_point and position() &lt;= $item_point + 5 and (position() mod 5)=1]"/>
    </xsl:element>

    <xsl:element name = "td">
    <xsl:value-of select = "item[position() &gt;= $item_point and position() &lt;= $item_point + 5 and (position() mod 5)=2]"/>
    </xsl:element>
    <xsl:element name = "td">
    <xsl:value-of select = "item[position() &gt;= $item_point and position() &lt;= $item_point + 5 and (position() mod 5)=3]"/>
    </xsl:element>
    <xsl:element name = "td">
    <xsl:value-of select = "item[position() &gt;= $item_point and position() &lt;= $item_point + 5 and (position() mod 5)=4]"/>
    </xsl:element>
    <xsl:element name = "td">
    <xsl:value-of select = "item[position() &gt;= $item_point and position() &lt;= $item_point + 5 and (position() mod 5)=0]"/>
    </xsl:element>
        </xsl:element>
    <xsl:call-template name = "output_item">
    <xsl:with-param name = "item_counts" select = "$item_counts"/>
    <xsl:with-param name = "item_point" select = "$item_point + 5"/>
    </xsl:call-template>
    </xsl:if>
    </xsl:template>
    </xsl:transform>
      

  8.   

    <xsl:template match = "jilu">改成<xsl:template match = "form">
      

  9.   

    sgdb(神天月晓):
    多谢更正!  :)
      

  10.   

    学到东西了,这些应用应该是xslt的精华了吧,长知识
      

  11.   

    <?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:template match="/">
    <html>
    <table>
    <xsl:for-each select="//Item[(position() - 9) mod 5 = 1]">
    <xsl:variable name="position" select="position()"/>
    <tr>
    <td width="15%" abbr="center">
    <xsl:value-of select="Value"/>
    </td>
    <td width="15%" abbr="center">
    <xsl:value-of select="../Item[position()=($position*5+5)]/Value"/>
    </td>
    <td width="15%" abbr="center">
    <xsl:value-of select="../Item[position()=$position*5+6]/Value"/>
    </td>
    <td width="15%" abbr="center">
    <xsl:value-of select="../Item[position()=$position*5+7]/Value"/>
    </td>
    <td width="15%" abbr="center">
    <xsl:value-of select="../Item[position()=$position*5+8]/Value"/>
    </td>
    </tr>
    </xsl:for-each>
    </table>
    </html>
    </xsl:template>
    </xsl:stylesheet>
      

  12.   

    对不起form是关键字不能用
      

  13.   

    分数太少,再加点sgdb(神天月晓)和AprilChen(babysky) 二位:再问一句:
    <xsl:element name = "table">
    ...
    </xsl:element>
    如何给table加上点控制属性,比如 align="center" border="1"等,我试着用<xsl:attribute>和<xsl:attribute-set>可是都不行,真郁闷 knight_qmh(辉):
    因为嵌套在 <xsl:for-each select="//Item[(position() - 9) mod 5 = 1]">中
    所以下面的Item路径我用各种方法控制但是都显示补出来
    .Item[...]出错
    //Form/Item, /FD/Form/Item不能显示结果,但是去掉外面的<xsl:for-each select="//Item[就可以显示最后一行
    ../Item不论外面有没有<xsl:for-each select="//Item都补显示结果
    我自己查资料感觉这三种都应该可以啊,麻烦您了