大家好!如何查看瀏覽器中的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