以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  xsl能不能实现排序后,生成几行几列的表格?我写了一个,但总不对~~  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=64156)


--  作者:fleawoo
--  发布时间:6/28/2008 10:23:00 AM

--  xsl能不能实现排序后,生成几行几列的表格?我写了一个,但总不对~~
//xml文件:
<data>
<port>
  <id>2 </id>
  <name>a </name>
</port>
<port>
  <id>1 </id>
  <name>b </name>
</port>
<port>
  <id>3 </id>
  <name>c </name>
</port>
</data>

//XSL
<xsl:template match="/data">
  <table bgcolor="snow" border="1" cellpadding="5" cellspacing="2" borderColor="darkorange" style="font-size:9pt">
  <xsl:for-each select="port[position() mod 3 = 1]">
          <xsl:sort select="id" order="ascending"/>
    <tr>
      <td width="33%" align="center" valign="middle">
        <xsl:apply-templates select="."/>
      </td>
      <td width="34%" align="center" valign="middle">
        <xsl:apply-templates select="following-sibling::port[position() = 1]"/>
      </td>
      <td width="33%" align="center" valign="middle">
        <xsl:apply-templates select="following-sibling::port[position() = 2]"/>
      </td>
    </tr>
  </xsl:for-each>
</table>
</xsl:template>

<xsl:template match="/data/port">
  <xsl:value-of select="name"/> <xsl:value-of select="id"/>
</xsl:template>

但仍未实现排序,我是想根据id升序生成一个动态表格.


--  作者:belinda_pjm
--  发布时间:6/30/2008 3:00:00 PM

--  
<xsl:output method ="html"/>
  <xsl:template match="/">
    <table bgcolor="snow" border="1" cellpadding="5" cellspacing="2" borderColor="darkorange" style="font-size:9pt">
      <xsl:for-each select="date/port">
        <xsl:sort select="id" order="ascending"/>
        <tr>
          <td width="33%" align="center" valign="middle">
            <xsl:value-of select ="id"/>
          </td>
          <td width="34%" align="center" valign="middle">
            <xsl:value-of select ="name"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms