我有一个格式如下的XML文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<COLLECTION>
<RECORD>
<FIELD fname="Description">Bike</FIELD>
<FIELD fname="Condition">New</FIELD>
<FIELD fname="Color">Red</FIELD>
</RECORD>
</COLLECTION>
我正在尝试使用XSLT对其进行格式化,但由于它不是通常的<description>Bike</description>
格式,我对下面的示例W3Schools代码没有太大帮助。任何帮助表示赞赏。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Description</th>
<th style="text-align:left">Condition</th>
</tr>
<xsl:for-each select="COLLECTION/RECORD">
<tr>
<td><xsl:value-of select="Description"/></td>
<td><xsl:value-of select="Condition"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:2)
使用子选择器:
<td><xsl:value-of select="FIELD[@fname='Description']"/></td>
等等。
您还可以考虑将XML预处理为更常规的格式。