我认为您遇到的问题是名称空间。您没有在 XSLT 中正确地考虑它们。查看示例提要,根元素如下:
<feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
这意味着,除非另有说明,否则所有元素都是名称空间的一部分,URI 为“http://www.w3.org/2005/Atom”。尽管您已经在 XSLT 中声明了这一点,但您并没有真正使用它,而且您的 XSLT 代码正在尝试匹配不属于任何名称空间的元素。
还有一个问题是您的 XSLT 也没有考虑提要元素。您需要做的是将初始模板匹配替换<xsl:template match="/">
为以下内容
<xsl:template match="/atom:feed">
你xsl:for-each会变成这样
<xsl:for-each select="atom:entry">
这是完整的 XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:im="http://itunes.apple.com/rss">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/atom:feed">
<tr>
<th>ID</th>
<th>Title</th>
</tr>
<xsl:for-each select="atom:entry">
<tr>
<td>
<xsl:value-of select="atom:id"/>
</td>
<td>
<xsl:value-of select="atom:title"/>
</td>
<td>
<xsl:value-of select="atom:category/@label"/>
</td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
这应该有望输出一些结果。
请注意,通常最好使用模板匹配,而不是xsl:for-each来鼓励模板的重用,以及使用更少缩进的更整洁的代码。这也可以
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:im="http://itunes.apple.com/rss">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/atom:feed">
<tr>
<th>ID</th>
<th>Title</th>
</tr>
<xsl:apply-templates select="atom:entry"/>
</xsl:template>
<xsl:template match="atom:entry">
<tr>
<td>
<xsl:value-of select="atom:id"/>
</td>
<td>
<xsl:value-of select="atom:title"/>
</td>
<td>
<xsl:value-of select="atom:category/@label"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>