+ -
当前位置:首页 → 问答吧 → 求助啊,help。编写一个xsl把person.xml以表格形式显示出来

求助啊,help。编写一个xsl把person.xml以表格形式显示出来

时间:2011-12-21

来源:互联网

求助。编写一个xsl把person.xml以表格形式显示出来。下面这个是一个简单的xml文档用“person.xsl”的样式表示出来的。


<? xml version="1.0"encoding="gb2312"?>
<! --File Name:person.xml-->
<? xml-stylesheet type="text/xsl"?>
<persons>
  <person>
  <name>张明</name>
  <code>008</code>
  <sex>男</sex>
  <E-mail>[email protected]</E-mail>
  </person>
  <person>
  <name>赵薇</name>
  <code>009</code>
  <sex>女</sex>
  <E-mail>[email protected]</E-mail>
  </person>
</persons>

作者: makai10001   发布时间: 2011-12-21

HTML code

<?xml version="1.0" encoding="gb2312"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>name</th>
        <th>code</th>
<th>sex</th>
<th>Email</th>

      </tr>
      <xsl:for-each select="persons/person">
      <tr>
        <td><xsl:value-of select="name"/></td>
        <td><xsl:value-of select="code"/></td>
<td><xsl:value-of select="sex"/></td>
<td><xsl:value-of select="E-mail"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

作者: zsx841021   发布时间: 2011-12-21