xsl 样式表不适用
xsl stylesheet won't apply
我对 XML 和 XSL/T 还很陌生,所以我还不太了解它。
所以我尝试从 http://edutechwiki.unige.ch/en/XSLT_Tutorial_-_Basics 制作一个教程,有一次我尝试制作一个小的 xsl 样式表,但它无法正确显示。有人看出我哪里出错了吗?
XLS:
<xsl:template match="student">
<html>
<head>
<title> <xsl:value-of select="firstname"/></title>
</head>
<body bgcolor="#ffffff">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="lastname">
<h1 align="center"> <xsl:value-of select="lastname"/> <xsl:apply-templates/> </h1>
</xsl:template>
XML:
<student>
<firstname>Tim</firstname>
<lastname>Spilka</lastname>
<nickname>Timi</nickname>
</student>
它在浏览器中显示为:
<html>
<head>
<META content="text/html; charset=UTF-16" http-equiv="Content-Type">
<title>Tim</title>
</META>
</head>
</html>
尸体就是没出现
<xsl:template match="lastname">
<h1 align="center">
<xsl:value-of select="lastname"/>
<xsl:apply-templates/>
</h1>
</xsl:template>
在匹配 lastname
的模板规则中,lastname
元素是上下文节点(或上下文项)。当您执行 select="lastname"
时,它意味着 select="child::lastname"
,即 select 名为 lastname
的上下文节点的子节点。您的 lastname
元素没有任何名为 lastname
的子元素,因此它 select 什么都没有。
你想要<xsl:value-of select="."/>
我对 XML 和 XSL/T 还很陌生,所以我还不太了解它。 所以我尝试从 http://edutechwiki.unige.ch/en/XSLT_Tutorial_-_Basics 制作一个教程,有一次我尝试制作一个小的 xsl 样式表,但它无法正确显示。有人看出我哪里出错了吗?
XLS:
<xsl:template match="student">
<html>
<head>
<title> <xsl:value-of select="firstname"/></title>
</head>
<body bgcolor="#ffffff">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="lastname">
<h1 align="center"> <xsl:value-of select="lastname"/> <xsl:apply-templates/> </h1>
</xsl:template>
XML:
<student>
<firstname>Tim</firstname>
<lastname>Spilka</lastname>
<nickname>Timi</nickname>
</student>
它在浏览器中显示为:
<html>
<head>
<META content="text/html; charset=UTF-16" http-equiv="Content-Type">
<title>Tim</title>
</META>
</head>
</html>
尸体就是没出现
<xsl:template match="lastname">
<h1 align="center">
<xsl:value-of select="lastname"/>
<xsl:apply-templates/>
</h1>
</xsl:template>
在匹配 lastname
的模板规则中,lastname
元素是上下文节点(或上下文项)。当您执行 select="lastname"
时,它意味着 select="child::lastname"
,即 select 名为 lastname
的上下文节点的子节点。您的 lastname
元素没有任何名为 lastname
的子元素,因此它 select 什么都没有。
你想要<xsl:value-of select="."/>