大家好!如何查看浏览器中的xsl输出?
我正在构建基于一些xml数据文件的网站,所以我选择使用XSLT来绑定浏览器中的样式表。
它起初效果很好,但最近随着模板变得越来越复杂,发生了一些奇怪的事情。
我使用“copy-of”元素将数据复制到样式表中。下面的代码:
<div class="section1">
<xsl:copy-of select="article/bodydata/*" />
</div>
所以,基本上,我复制“bodydata”节点的所有子元素融入< DIV/>。
但它不起作用。例如,我在bodydata中有一个< img/>元素,如果我访问浏览器中的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>
,结果是这样的: img元素就会消失。
接下来,我将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>
这里的结果是: 并显示图像。
所以我想知道这里有什么问题。
你是什么意思,“那个图像没有出现......”你没看到“”“?或者你想看到图片本身显示? – 2012-08-14 12:14:46
@DimitreNovatchev我看到了img元素在dom树中,但宽度和高度都为0. – 2012-08-14 12:15:31
这意味着源XML文档中的宽度和高度都为0('xsl:copy-of'复制节点时没有任何更改)因此,要更改这些属性的值应该使用与'xsl:copy-of'不同的东西 – 2012-08-14 12:23:25