【发布时间】:2014-11-07 13:57:31
【问题描述】:
我正在使用 XSLT 样式表将爱丽丝梦游仙境文本的简单 XML 文件呈现为 HTML。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Alice.xsl"?>
<book>
<title>Alice's Adventures in Wonderland</title>
<text>
<chapter>
<chapter_heading>Chapter I. Down the Rabbit-Hole</chapter_heading>
<p>Alice was beginning to get very tired of sitting by her sister on the
bank, and of having nothing to do: once or twice she had peeped into the
book her sister was reading, but it had no pictures or conversations in
it, 'and what is the use of a book,' thought Alice 'without pictures or
conversations?'</p>
<p>So she was considering in her own mind (as well as she could, for the
hot day made her feel very sleepy and stupid), whether the pleasure
of making a daisy-chain would be worth the trouble of getting up and
picking the daisies, when suddenly a White Rabbit with pink eyes ran
close by her.</p>
</chapter>
</text>
</book>
简单的东西。我们正在尝试使用以下代码仅将章节的标题和段落输出到 HTML 中的标签中:
<?xml version="1.0" encoding="UTF-8"?><!-- DWXMLSource="http://www.w3.org/1999/XSL/Transform" -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<article>
<xsl:apply-templates/>
</article>
</body>
</html>
</xsl:template>
<xsl:template match="title"/>
<xsl:template match="chapter">
<h3>
<xsl:apply-templates select="chapter_heading"/>
</h3>
<div class="paragraph">
<xsl:apply-templates select="p"/>
</div>
</xsl:template>
</xsl:stylesheet>
但是一旦在浏览器中打开 XML 文件,XML 中的所有单独的“p”标签都会组合到 HTML 中的一个大“div”中。
我们的团队显然对 XSL 非常陌生,但就我们能够研究的情况而言,我们不知道为什么它不能顺利运行。任何帮助将不胜感激!
【问题讨论】:
标签: html xml xslt xhtml xslt-2.0