你需要对每一个循环
student
并选择
firstname
以获得所需的输出。
http://xsltransform.net/ncntCSr/3
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="class" />
</body>
</html>
</xsl:template>
<xsl:template match="class" >
<xsl:for-each select="student">
<xsl:apply-templates select="firstname"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="firstname" >
<h1>
name : <xsl:value-of select="name"/>
<xsl:text> </xsl:text>
p2 : <xsl:value-of select="p2"/>
</h1>
</xsl:template>
</xsl:stylesheet>