xsl xml解析、转换、属性
这是我的 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...如果我这样做的话 value-of select="image “...它只能获取从 xml 文件读取的第一个图像...那么我如何将每个艺术家的排名 1、2、3 转移到正确的 xsl 中?
this is my xml file. i want to use xslt to transfer them into browser readerable information
<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>
and here is my solution in my xsl file:
<td><xsl:value-of select="image"/></td>
<td><xsl:value-of select="image"/></td>
<td><xsl:value-of select="image"/></td>
but as u can see artist has rank 1,2,3... if i do it like value-of select="image"... it can only get the 1st image it read from xml file... so how do i transfer each artist rank1,2,3 in to proper xsl ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加
来获取每个图像,否则您将继续获取第一个匹配项。生产
You need to add an
<xsl:for-each select='image'>
to get every image, otherwise you'll just keep getting the first match.Produces