我正在尝试解析 xml 文件并将节点按水平顺序放置;然而,由于我的水平是(非常)初学者,我所有的方法都失败了;我可以实现的是一个包含所有 xml 元素的“正常”表。
文件在这里- xmlplayground
我想要实现的是
PROD | HOST 1| HOST 2 | HOST 3 | HOST 4 |
disk | value | value | value | value |
etc..| ... | ... | .... | ... |
INTE | HOST 5| HOST 6 | HOST 7 |
etc..| value | value | value |
TEST | HOST 8|
etc | values|
任何提示表示赞赏;谢谢
#
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="systatus.xsl"?>
<systatus>
<environment name="prod">
<node name="HOST 1">
<OS>
<disk> Total 197G </disk>
<disk> Use% 29% </disk>
<ip> 192.168.169.193/24 bond0 </ip>
<osver> RHEL </osver>
<kernel> 2.6.32-358.6.1.el6.x86_64 </kernel>
<TotalMemory> 15939 </TotalMemory>
<package> java-1.6.0-sun-devel-1.6.0.45-1jpp.1.el6.x86_64 </package>
<package> tomcat6-el-2.1-api-6.0.24-52.el6_4.noarch </package>
<package> httpd-2.2.15-26.el6.x86_64 </package>
<package> java-1.6.0-sun-1.6.0.45-1jpp.1.el6.x86_64 </package>
<package> java-1.5.0-gcj-1.5.0.0-29.1.el6.x86_64 </package>
<package> tomcat6-servlet-2.5-api-6.0.24-52.el6_4.noarch </package>
<package> tomcat6-jsp-2.1-api-6.0.24-52.el6_4.noarch </package>
<package> tomcat6-lib-6.0.24-52.el6_4.noarch </package>
<package> httpd-tools-2.2.15-26.el6.x86_64 </package>
<package> jakarta-commons-httpclient-3.1-0.7.el6_3.x86_64 </package>
<package> java_cup-0.10k-5.el6.x86_64 </package>
<package> tomcat6-6.0.24-52.el6_4.noarch </package>
</OS>
<App>
<MinMemory> 4000 </MinMemory>
<MaxMemory> 8000 </MaxMemory>
<app_version> 5.5.0 </app_version>
<module> -rwxr-xr-x 1 root root 618184 Aug 9 12:20 mod_module.so </module>
</App>
</node>
......
和
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="environment">
<html>
<body>
<h2><b><xsl:value-of select="@name" /></b></h2>
<table border="1">
<xsl:for-each select="node">
<td bgcolor="#9acd32" colspan="2"><b>
<xsl:value-of select="@name" /></b>
</td>
<xsl:for-each select="*/*">
<tr>
<td><xsl:value-of select="name(.)"/></td>
<td><xsl:value-of select="." /></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>