I have the following XML 法典 and I try to display by using XSLT. How to select the fieldname and return all value in a table. I tried but it won t work, just only return first record ( username and user ). Please help, many thanks.
XML 法典
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xml_list_new.xsl"?>
<root>
<record>
<fieldname>username</fieldname>
<value>user</value>
<fieldname>ipaddress</fieldname>
<value>127.0.0.1</value>
<fieldname>lastaction</fieldname>
<value>2011-06-13 00:53:05</value>
<fieldname>sessionid</fieldname>
<value>h0atrutpu5vgrvuf3ipledfbvl1</value>
</record>
<record>
<fieldname>username</fieldname>
<value>admin</value>
<fieldname>ipaddress</fieldname>
<value>127.0.0.1</value>
<fieldname>lastaction</fieldname>
<value>2011-06-12 00:43:53</value>
<fieldname>sessionid</fieldname>
<value>nnbdofsdq4sd7e3def3hnid9</value>
</record>
<record>
<fieldname>username</fieldname>
<value>ccm</value>
<fieldname>ipaddress</fieldname>
<value>127.0.0.1</value>
<fieldname>lastaction</fieldname>
<value>2011-06-10 00:30:22</value>
<fieldname>sessionid</fieldname>
<value>di34bndffgrt48cmkl08d8e4</value>
</record>
</root>
XSLT 代码
<?xml version= 1.0 ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method= html />
<xsl:param name="title">XML List</xsl:param>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title><xsl:value-of select="$title"/></title>
<style type="text/css">
<![CDATA[
caption { font-weight: bold; }
th {
background: #2C3033;
color: #fff;
font-family: arial;
font-weight: bold;
font-size: 12px;
}
tr {
font-family: arial;
color: #000;
font-size: 12px;
background: #E0E0E0;
}
]]>
</style>
</head>
<body>
<div class="center" style="width: 800px; margin: 0 auto">
<table border="0" style="width: 800px">
<caption><xsl:value-of select="$title"/></caption>
<thead>
<tr>
<xsl:for-each select="root/record">
<th >
<xsl:value-of select="fieldname"/>
</th>
</xsl:for-each>
</tr>
</thead>
<tbody>
<xsl:for-each select="root/record">
<tr>
<td ><xsl:value-of select="value"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>