每个人!
我正在构建一个基于一些 xml 数据文件的网站,因此我选择使用 XSLT 来绑定浏览器中的样式表。
一开始它工作得很好,但最近,随着模板变得越来越复杂,一些奇怪的事情发生了。
我使用“copy-of”元素将数据复制到样式表中。这是代码:
<div class="section1">
<xsl:copy-of select="article/bodydata/*" />
</div>
因此,基本上,我将“bodydata”节点的所有子元素复制到
中。
但这不起作用。例如,我在 bodydata 中有一个 元素,如果我在浏览器中访问 xml 文件,则该图像不会出现。另一方面,如果我手动将“bodydata”元素复制到该 div 中,并将 .xsl 文件制作为 .html 文件,则该图像确实会显示。
那么,我的问题是,我可以在浏览器中查看 xml 数据和 xsl 数据的组合输出吗?我需要延期还是什么?
对可能出现的问题有什么建议吗?我对 xslt 还很陌生,所以我似乎误解了 XSLT 的真正用途。谢谢!
UPDATE
为了说明这个问题,我写了一个小例子。
首先,我创建了一个示例 xml 数据文件:
<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="article.xsl"?>
<article>
<bodydata>
<center>
<img alt="sample" src="http://www.google.com/logos/classicplus.png" />
</center>
<p>
<data class="tts_data">
this is the paragraph.
</data>
</p>
<p>
<data class="tts_data">this is the second paragraph</data>
<data class="tts_data">more data</data>
<data class="tts_data">...</data>
</p>
</bodydata>
</article>
所以,你可以看到,“bodydata”元素中的所有节点都是需要在网页上显示的html元素。为了显示这一点,我创建了一个示例 xsl 文件。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex" />
</head>
<body>
<article>
<header>
header of the article
</header>
<section>
<xsl:copy-of select="article/bodydata/*" />
</section>
</article>
<footer>
footer part of the page
</footer>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
And the result is like this:
The img element just disappears.
接下来,我将 bodydata 元素复制到节部分,并形成一个新的 html 文件。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex" />
</head>
<body>
<article>
<header>
header of the article
</header>
<section>
<center>
<img alt="sample" src="http://www.google.com/logos/classicplus.png" />
</center>
<p>
<data class="tts_data">
this is the paragraph.
</data>
</p>
<p>
<data class="tts_data">
this is the second paragraph,
</data>
<data class="tts_data">
more data
</data>
<data class="tts_data">...</data>
</p>
</section>
</article>
<footer>
footer part of the page
</footer>
</body>
</html>
And the result here is:
And the image appears.
所以我想知道这里出了什么问题。