我试图使这个(xml 1.0)代码工作。我对此很陌生,并且已经在尝试不同的方式时筋疲力尽。有人知道我的错误吗?
<xsl:for-each select="News/Sport">
<xsl:if test="local-name()='Basketball'">
<p>
<xsl:text>Basketball Sport</xsl:text>
</p>
<xsl:value-of select="News/Sport/Basketball/Phrases/Phrase"/>
</xsl:if>
</xsl:for-each>
当我将其转换为 HTML 文件时,内容不会显示出来。当我删除xsl:for each
并且xsl:if statements
内容成功呈现时。我只希望首先检查内容(如果它在 XML 文件中可用),如果是,那么它是从 XML 内容中获取的。
预先感谢您的帮助!
编辑:
这是我的 XML 代码
<News>
<Sport>
<Basketball>
<Phrases>
<Phrase>Zach Randolph recovered the opening tipoff in Game 1 of the Western Conference Finals, and he didn’t touch the ball again until the possession following the Grizzlies’ first timeout.
</Phrase>
<Phrases>
</Basketball>
</Sport>
</News>
编辑2:
你能告诉我为什么我不能在下面的函数中应用模板吗?现在只有文字有效:(
<xsl:for-each select="News/Sport[Basketball]">
<xsl:apply-templates select="News/Sport/*" />
</xsl:for-each>
<xsl:template match="Basketball">
<p>
<xsl:text>Basketball Sport</xsl:text>
</p>
<xsl:apply-templates select="Phrases/Phrase"/>
</xsl:template>