阅读:5612回复:4
请教有关XSL的显示问题
小弟最近在学习XML+XSL的页面设计,结果遇到这样的问题。按照之前找到的资料,FF需要用<?xml-stylesheet>标签才能链接到XSL,试验成功,可是奇怪的是,在XSL中链接的外部CSS始终没有生效。
我用IE看就没问题,用FF和Opera看都是怪怪的,甚至连<A>标签都不能正常点击。 代码如下,请各位指点一下! test.xml <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="./test.xsl"?> <PAGEDATA> <test><![CDATA[This is a test c!!!]]></test> </PAGEDATA> test.xsl <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <xsl:template match="/"> <html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Test Page</title> <link href="main.css" rel="stylesheet" type="text/css" media="screen, projection" /> </head> <body> <a><xsl:attribute name="HREF">https://www.firefox.net.cn/</xsl:attribute><xsl:value-of select="/PAGEDATA/test" /></a> </body> </html> </xsl:template> </xsl:stylesheet> |
|
1楼#
发布于:2007-04-17 16:33
把大写的HREF改为小写的href
因为你用的xhtml。 |
|
2楼#
发布于:2007-04-17 16:33
谢谢解答,好像的确是标准的问题。昨天查了好多教程和W3的官方资料,解决的方法是在声明中加入transform的类型:
<xsl:output method="html" version="4.01" encoding="UTF-8" /> 不过现在又发现另外一个问题。我在<style>中定义了body的属性,代码如下: <style type="text/css"> body { background-color: #CC0000; } </style> 这个代码在IE和Opera中都可以正常显示,但是在FF下,背景仍然是白花花的一片啊……郁闷…… 整个XSL的代码如下: <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <xsl:output method="html" version="4.01" encoding="UTF-8" /> <xsl:template match="/"> <html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Test Page</title> <style type="text/css"> body { font-size: 14px; color: #333333; background-color: yellow; } </style> </head> <body> <a><xsl:attribute name="HREF">https://www.firefox.net.cn/</xsl:attribute><xsl:value-of select="/PAGEDATA/test" /></a><br /><br />This is normal text. </body> </html> </xsl:template> </xsl:stylesheet> 请问是什么问题呢? |
|
3楼#
发布于:2007-04-17 16:33
又看了一下,我注意到可能是doctype声明的问题,貌似html 4.01不支持background-color的css表达方式?可是xsl只能转换目标为xml或html,没有能够转换xhtml的选项。
在<xsl:output>中有个doctype-public的attribute,看说明是可以用来定义doctype的。不过传统的doctype声明有两部分组成,我不知道这个东东怎么写。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd"> |
|
4楼#
发布于:2007-04-17 16:33
折腾了一天,终于搞定了。声明如下:
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xhtml"> <xsl:output method="xml" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" /> |
|