我编写了以下XML代码:
<game id="1">
<title>Call of duty</title>
<release>
<year>2007</year>
<month>06</month>
<day>27</day>
</release>
<publisher>Infinity</publisher>
<engine>Source</engine>
<platforms>
<platform>Windows</platform>
<platform>Xbox</platform>
<platform>wii</platform>
</platforms>
</game>
我正在尝试显示游戏的ID,在这种情况下是数字1.我怎么能这样做?我写了以下XSL代码:
<xsl:apply-templates select="game"/>
<xsl:template match="game">
Game: <xsl:value-of select="//game/@id"/>
<br />
</xsl:template>
谢谢
答案 0 :(得分:2)
只需
<xsl:template match="game">
<xsl:text>Game: </xsl:text>
<xsl:value-of select="@id"/>
<br/>
</xsl:template>
当您匹配游戏时,您已经在节点中,因此无需在路径中再次指定它。