这是我的xml文件。我想使用xslt将它们传输到浏览器可重用信息
<artist rank="1">
<name>Dream Theater</name>
<playcount>1438</playcount>
<mbid>28503ab7-8bf2-4666-a7bd-2644bfc7cb1d</mbid>
<url>http://www.last.fm/music/Dream+Theater</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/5535004.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/5535004.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/5535004.jpg</image>
</artist>
<artist rank="2">
<name>Miles Davis</name>
<playcount>748</playcount>
<mbid>561d854a-6a28-4aa7-8c99-323e6ce46c2a</mbid>
<url>http://www.last.fm/music/Miles+Davis</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/4971157.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/4971157.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/4971157.jpg</image>
</artist>
<artist rank="3">
<name>Dire Straits</name>
<playcount>732</playcount>
<mbid>614e3804-7d34-41ba-857f-811bad7c2b7a</mbid>
<url>http://www.last.fm/music/Dire+Straits</url>
<streamable>1</streamable>
<image size="small">http://userserve-ak.last.fm/serve/34/135149.jpg</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/135149.jpg</image>
<image size="large">http://userserve-ak.last.fm/serve/126/135149.jpg</image>
</artist>
这是我的xsl文件中的解决方案:
<td><xsl:value-of select="image"/></td>
<td><xsl:value-of select="image"/></td>
<td><xsl:value-of select="image"/></td>
但是你可以看到艺术家的排名是1,2,3 ...如果我这样做就像select =“image”...它只能得到它从xml文件中读取的第一张图片......那么如何将每个艺术家的排名1,2,3转移到正确的xsl?
答案 0 :(得分:1)
您需要添加<xsl:for-each select='image'>
来获取每张图片,否则您将继续获得第一场比赛。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<table>
<xsl:for-each select='/xml/artist'>
<xsl:sort order="ascending" data-type="number" select="@rank"/>
<tr>
<td><xsl:value-of select='name'/></td>
<xsl:for-each select='image'>
<td><xsl:value-of select='.'/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
制作
<table>
<tr>
<td>Dream Theater</td>
<td>http://userserve-ak.last.fm/serve/34/5535004.jpg</td>
<td>http://userserve-ak.last.fm/serve/64/5535004.jpg</td>
<td>http://userserve-ak.last.fm/serve/126/5535004.jpg</td>
</tr>
<tr>
<td>Miles Davis</td>
<td>http://userserve-ak.last.fm/serve/34/4971157.jpg</td>
<td>http://userserve-ak.last.fm/serve/64/4971157.jpg</td>
<td>http://userserve-ak.last.fm/serve/126/4971157.jpg</td>
</tr>
<tr>
<td>Dire Straits</td>
<td>http://userserve-ak.last.fm/serve/34/135149.jpg</td>
<td>http://userserve-ak.last.fm/serve/64/135149.jpg</td>
<td>http://userserve-ak.last.fm/serve/126/135149.jpg</td>
</tr>
</table>