【发布时间】:2017-09-02 03:11:51
【问题描述】:
当我尝试在 Firefox 中加载我的 xml 时收到此错误消息,当我尝试在 Safari 和 Google 中加载时收到空白页面。我错过了一个错误吗? 我的造型要求:
- 年份---粗体
- 标题----深蓝色字重900
- 导演 - 深绿色,粗体
- 演员 --- 男性为蓝色,女性为粉色
- 类型----斜体和下划线
- 时间----深红色,粗体,下划线
XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="lab4_part2.xsl"?>
<streaming>
<movies>
<year>1985</year>
<title>The Breakfast Club</title>
<director>John Hughes</director>
<actors>
<male>Emilio Estevez</male>
<male>Paul Gleason</male>
<male>Anthony Micheal Hall</male>
<male>Judd Nelson</male>
<female>Molly Ringwald</female>
<female>Ally Sheedy</female>
</actors>
<type>Comedy, Drama</type>
<time>97</time>
</movies>
<movies>
<year>1994</year>
<title>Forrest Gump</title>
<director>Robert Zemeckis</director>
<actors>
<male>Tom Hanks</male>
<male>Mykelti Williamson</male>
<male>Gary Sinise</male>
<male>Haley Joel Osment</male>
<female>Sally Field</female>
<female>Robin Wright</female>
</actors>
<type>Comedy, Drama, Romance</type>
<time>142</time>
</movies>
</streaming>
XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="streaming/movies">
<div>
<p><xsl:value-of select="year" style="font-weight:bold;"/></p>
<p><xsl:value-of select="title" style="color:DarkBlue; font-
weight:900;"/></p>
<p><xsl:value-of select="director" style="color:DarkGreen; font-
weight:bold;"/></p>
<p>Actors</p>
<ul>
<xsl:for-each select="streaming/movies/actors">
<xsl:if test="name() = 'male'">
<li><xsl:value-of select="male" style="color:blue;"/></li>
</xsl:if>
<xsl:if test="name() = 'female'">
<li><xsl:value-of select="male" style="color:pink;"/></li>
</xsl:if>
</xsl:for-each>
</ul>
<p><xsl:value-of select="type" style="text-decoration:underline;
font-style:italic;"/></p>
<p><xsl:value-of select="time" style="color:DarkRed; text-
decoration:underline; font-weight:bold;"/></p>
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
您已被告知错误是什么,但问题的根本原因是您正在运行此样式表而没有看到错误消息。通常,在浏览器中运行 XSLT 并不是最好的开发环境,但大多数浏览器确实会在开发者控制台中提供诊断信息,您需要熟悉如何找到它们。
-
我还推荐了xsltransform.net 作为测试 XSLT 的工具,但不幸的是,该服务目前不可用...
-
@TimC 我真的认为你应该发布一个规范的答案。该服务现已备份。
标签: html xml xslt transform styling