XML 文档未注册 XSL 样式表? [英] XML Document not registering XSL stylesheet?
问题描述
我一直试图用我的 XSL 样式表测试链接我的 XML 文档,但是它所做的只是显示 XML 文档的信息并忽略我的模板,我不知道为什么.
I've been trying to test-link my XML document with my XSL stylesheet, however it all it does is display the XML doc's information and ignores my templates, and I have no clue why.
movies.xml 文档
movies.xml document
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="movies.xsl"?>
<movieRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.example.com/comicbooks/movies/ns"
xsi:schemaLocation="http://www.example.com/comicbooks/movies/ns movies.xsd">
<movie>
<movieTitle>Captain America: Civil War</movieTitle>
<genre>Action, Adventure, Sci-Fi</genre>
<rating>8.13</rating>
<length>147 min</length>
<releaseDate>May 6th, 2016</releaseDate>
</movie>
</movieRoot>
movies.xsl 样式表(我也尝试过 apply-templates select="movies")
movies.xsl stylesheet (I've also tried apply-templates select="movies" as well)
<?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>
<link ref="stylesheet" type="text/css" href="movies.css" />
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="movie">
<p>Movies</p>
</xsl:template>
</xsl:stylesheet>
电影.css
body {color:blue;}
推荐答案
您的 xml 文件具有默认命名空间.
您需要在 xsl 文件中声明这个命名空间并使用它.
Your xml file has a default namespace.
You need to declare this namespace in the xsl file and use it.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://www.example.com/comicbooks/movies/ns">
<xsl:template match="ns:movie">
你还有一个错字:ref
而不是 rel
.
Also you have a typo: ref
instead of rel
.
<link rel="stylesheet" type="text/css" href="movies.css" />
<小时>
修改后的xsl文件应该是这样的:
After modifying the xsl file should look like this:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://www.example.com/comicbooks/movies/ns">
<xsl:template match="/">
<html>
<link rel="stylesheet" type="text/css" href="movies.css" />
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="ns:movie">
<p>Movies</p>
</xsl:template>
</xsl:stylesheet>
其他文件保持不变.
这篇关于XML 文档未注册 XSL 样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!