【发布时间】:2014-07-11 11:46:46
【问题描述】:
我正在尝试自学 XSLT。这可能是一个非常基本的问题,但经过大量搜索,以及网络上的其他网站,我仍然无法解决这个问题。
我一直在尝试重新创建此问题中描述的场景:How can you deal with embedded XML tags in XSLT?
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>
这是 XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<html>
<head />
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="/*">
<ul>
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match="favoriteMovie">
<li><xsl:copy-of select="node()"/></li>
</xsl:template>
</xsl:stylesheet>
这适用于这个特定的示例。但是当我添加另一个“最喜欢的电影”时......
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.html.xsl"?>
<favoriteMovies>
<favoriteMovie>the <i>Star Wars</i> saga</favoriteMovie>
</favoriteMovies>
<favoriteMovies>
<favoriteMovie>the <i>Godfather</i> trilogy</favoriteMovie>
</favoriteMovies>
我得到的只是一个错误......
XML 解析错误:文档元素位置后出现垃圾: localhost:8888/test.xml 第 6 行,第 1 列: ^
我需要进行哪些更改才能使其正常工作?
【问题讨论】: