以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  如何用xslt输出复杂的html表格????紧急!!!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=19987)


--  作者:zhixue_zhang
--  发布时间:6/29/2005 1:46:00 PM

--  如何用xslt输出复杂的html表格????紧急!!!
如题,xml文件如下:
<?xml version="1.0" encoding="GB2312"?>
<nodes name="北京">
  <nodes name="上地">
   <node name="五街">
    <param name="温度" />
    <param name="压力" />
   </node>
   <node name="七街">
    <param name="温度" />
    <param name="压力" />
   </node>
  </nodes>
  <nodes name="西三旗">
   <node name="育新">
    <param name="温度" />
    <param name="压力" />
   </node>
   <node name="黄土店">
    <param name="温度" />
    <param name="压力" />
   </node>
  </nodes>
</nodes>

要输出下面这样的表格,如图:


此主题相关图片如下:
按此在新窗口浏览图片


--  作者:jx27
--  发布时间:7/2/2005 9:23:00 AM

--  
不好意思,本事没到家,把你的XML稍微改了一下。
1)中文我改成英文了
2)我加了一个MODE,因为你的NODES有2种不同的意思。
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xue.xsl"?>

<nodes name="Beijing">
  <nodes name="Shangdi" mode="sub">
   <node name="wujie">
    <param name="Temp" />
    <param name="Pressure" />
   </node>
   <node name="Qijie">
    <param name="Temp" />
    <param name="Pressure" />
   </node>
  </nodes>
  <nodes name="Xisanqi" mode="sub">
   <node name="yuxin">
    <param name="Temp" />
    <param name="Pressure" />
   </node>
   <node name="Huangtudi">
    <param name="Temp" />
    <param name="Pressure" />
   </node>
  </nodes>
</nodes>


/=====================================below is my xslt
<?xml version="1.0" encoding="utf-8"?>
<!--
Author Name: Xue Jun (0226318)
Contact: jx27@waikato.ac.nz
Copyright: Waikato Uni
Version:1.0(updated @ 02/07/2005)
Last Updated: 02 July 2005
 -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
 <xsl:output method="xhtml" version="1.0" indent="yes"/>
 <xsl:template match="/">
  <xsl:apply-templates select="*"/>
 </xsl:template>
 <!--
                The following template is applied to the root element of the
           nodes and generates the basic xhtml document structure.
        -->
 <xsl:template match="nodes">
  <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
    <title>TABLE</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="author" content="XUE JUN"/>
   </head>
   <body xml:lang="en">
    <h1>TABLE</h1>
    <hr/>
    <!-- Seperate Line-->
    <table border="1" width="100%" align="center">
     <tr>
      <!--Show 1st row-->
      <th align="center" width="100%" colspan="8">
       <xsl:value-of select="@name"/>
      </th>
     </tr>
     <tr>
      <!--2nd row-->
      <xsl:apply-templates select="nodes" mode="sub"/>
     </tr>
     <tr>
      <!--3rd row-->
      <xsl:apply-templates select="//node"/>
     </tr>
     <tr>
      <!--4th row-->
      <xsl:apply-templates select="//param"/>
     </tr>
    </table>
   </body>
  </html>
 </xsl:template>
 <!--&&&&&&&&&&&&&&&&&&&&&&&&   nodes    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&-->
 <xsl:template match="nodes" mode="sub">
  <th align="center" width="50%" colspan="4">
   <xsl:value-of select="@name"/>
  </th>
 </xsl:template>
 <!--&&&&&&&&&&&&&&&&&&&&&&&&   node    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&-->
 <xsl:template match="node">
  <th align="center" width="25%" colspan="2">
   <xsl:value-of select="@name"/>
  </th>
 </xsl:template>
 <!--&&&&&&&&&&&&&&&&&&&&&&&&   param    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&-->
 <xsl:template match="param">
  <th align="center" width="13%">
   <xsl:value-of select="@name"/>
  </th>
 </xsl:template>
</xsl:stylesheet>
/=======================



此主题相关图片如下:
按此在新窗口浏览图片


[此贴子已经被作者于2005-7-2 9:48:03编辑过]

W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms