【发布时间】:2015-06-17 07:50:20
【问题描述】:
我有一个xml和xsl,如下图我想显示xml中的所有值
输入 XML
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<test>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
</test>
<test1>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</test1>
</cd>
<cd>
<test>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
</test>
<test1>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</test1>
</cd>
</catalog>
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<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 style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
<!--<th style="text-align:left">country</th>
<th style="text-align:left">company</th>-->
</tr>
<xsl:for-each select="catalog/cd/test">
<tr>
<td><xsl:value-of select="//title"/></td>
<td><xsl:value-of select="//artist"/></td>
<!--<td><xsl:value-of select="//country"/></td>
<td><xsl:value-of select="//company"/></td>-->
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我想显示所有 cd 循环的标题、艺术家、国家和公司值。通过上面的代码,我只能显示第一个值。任何人都可以帮助我如何遍历 xml 并显示所有值。
【问题讨论】: