XSLT 不显示转换后的内容
XSLT does not diplay transformed content
我正在学习 XSLT。
我的 XML 文件中有这个:
<corpus>
<article>
<header>
<copyright> Copyright © contrapress media GmbH </copyright>
<identifier> T990226.149 TAZ Nr. 5772 </identifier>
<page> 15 </page>
<date> 26.02.1999 </date>
<length> 298 Zeilen </length>
<texttype> Interview </texttype>
<author> Maximilian Dax </author>
</header>
<body>
<headings>
<title>
<token lemma="@quot;" wclass="$(" type="open"> " </token>
<token wclass="PDS" lemma="d"> Das </token>
<token wclass="VVFIN" lemma="nennen"> nenne </token>
<token wclass="PPER" lemma="ich"> ich </token>
<token wclass="NN" lemma="Selbstreferenz"> Selbstreferenz </token>
<token wclass="$." lemma="!"> ! </token>
<token lemma="@quot;" wclass="$(" type="close"> " </token>
</title>
</headings>
</body>
</article>
</corpus>
并且我尝试使用 XSLT 在 html 中显示它:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/corpus">
<xsl:apply-templates select="/corpus"></xsl:apply-templates>
</xsl:template>
<xsl:template match="//article[1]/body/headings/title//token">
<html>
<head>TextvomTab</head>
<body>
<h2><xsl:value-of select="."/></h2>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这似乎不起作用。每当我在氧气上按下 "transform" 键时,我得到的只是一个空白的 html 页面。
当你这样做时:
<xsl:template match="/corpus">
<xsl:apply-templates select="/corpus"></xsl:apply-templates>
</xsl:template>
您正在将 XSLT 处理器送入无限循环,一遍又一遍地应用相同的模板。
我认为你想做的:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/corpus">
<html>
<head>
<title>TextvomTab</title>
</head>
<body>
<h2>
<xsl:apply-templates select="article[1]/body/headings/title/token"/>
</h2>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这将产生以下结果:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TextvomTab</title>
</head>
<body>
<h2> " Das nenne ich Selbstreferenz ! " </h2>
</body>
</html>
我正在学习 XSLT。 我的 XML 文件中有这个:
<corpus>
<article>
<header>
<copyright> Copyright © contrapress media GmbH </copyright>
<identifier> T990226.149 TAZ Nr. 5772 </identifier>
<page> 15 </page>
<date> 26.02.1999 </date>
<length> 298 Zeilen </length>
<texttype> Interview </texttype>
<author> Maximilian Dax </author>
</header>
<body>
<headings>
<title>
<token lemma="@quot;" wclass="$(" type="open"> " </token>
<token wclass="PDS" lemma="d"> Das </token>
<token wclass="VVFIN" lemma="nennen"> nenne </token>
<token wclass="PPER" lemma="ich"> ich </token>
<token wclass="NN" lemma="Selbstreferenz"> Selbstreferenz </token>
<token wclass="$." lemma="!"> ! </token>
<token lemma="@quot;" wclass="$(" type="close"> " </token>
</title>
</headings>
</body>
</article>
</corpus>
并且我尝试使用 XSLT 在 html 中显示它:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/corpus">
<xsl:apply-templates select="/corpus"></xsl:apply-templates>
</xsl:template>
<xsl:template match="//article[1]/body/headings/title//token">
<html>
<head>TextvomTab</head>
<body>
<h2><xsl:value-of select="."/></h2>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这似乎不起作用。每当我在氧气上按下 "transform" 键时,我得到的只是一个空白的 html 页面。
当你这样做时:
<xsl:template match="/corpus">
<xsl:apply-templates select="/corpus"></xsl:apply-templates>
</xsl:template>
您正在将 XSLT 处理器送入无限循环,一遍又一遍地应用相同的模板。
我认为你想做的:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/corpus">
<html>
<head>
<title>TextvomTab</title>
</head>
<body>
<h2>
<xsl:apply-templates select="article[1]/body/headings/title/token"/>
</h2>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这将产生以下结果:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TextvomTab</title>
</head>
<body>
<h2> " Das nenne ich Selbstreferenz ! " </h2>
</body>
</html>