<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="biomirror.xsl"?>
<Thread>
<Title> Some thread title </Title>
<Posts>
<Post>
<Author> Me </Author>
<Body>
This is the post body, which <b>may</b> have embedded XHTML, including all sorts of things like:<br />
<div class="quote">Quotes</div>
I know it's XHTML, though, the program spitting out XML verifies that.
</Body>
</Post>
</Posts>
</Thread>
我需要将它们格式化为可读的线程,所以我使用CSS样式表和XSL样式表。CSS很管用,我知道这没什么问题。我的问题似乎是XSL,因为Firefox没有解析任何嵌入的XHTML。在IE中,它工作得很好,并且有适当的格式,但在Firefox中,它完全是纯文本。我假设这与它在输出之前被转义有关,但我不知道如何防止这种情况。
XSL是:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
omit-xml-declaration="yes"
method="xml"
media-type="application/xhtml+xml"
indent="no"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
/>
<xsl:template match="Posts">
<xsl:for-each select="Post">
<tr xmlns="http://www.w3.org/1999/xhtml" class="Post">
<td>
<div>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="Author">
<xsl:value-of select="Author"/>
</td>
<td class="Date">
Post <xsl:value-of select="PostID"/>
<xsl:choose>
<xsl:when test="count(LastPost) > 0">
(lastpost)
</xsl:when>
</xsl:choose> at <xsl:value-of select="Date"/>
</td>
</tr>
</table>
</div>
<div class="Body">
<xsl:copy-of select="Body" />
</div>
<xsl:choose>
<xsl:when test="count(Sig) = 1">
<div class="Sig">
<xsl:value-of disable-output-escaping="yes" select="Sig"/>
</div>
</xsl:when>
<xsl:when test="count(Sig) = 0">
<div class="SigFooter"> </div>
</xsl:when>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="Thread">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<xsl:choose>
<xsl:when test="count(Title) = 1">
<title>
<xsl:value-of select="Title"/>
</title>
</xsl:when>
</xsl:choose>
<link href="resources/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table class="Thread" align="center" width="90%" height="95%" cellpadding="2em">
<tr>
<td colspan="3">
<div class="Title">
<xsl:value-of select="Title"/>
<br />
<a href="whatis.xml">
<img src="resources/banner.png" />
</a>
</div>
</td>
</tr>
<xsl:apply-templates select="Posts"/>
<tr height="100%">
<td valign="bottom">
<div class="Footer">
Footer message n stuff
</div>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
现在,我读到这个问题:
XSLT: Parsing HTML embedded in XML?
并尝试将其集成到我的XML和XSL中(如上所示)。不过,在Firefox中仍然不起作用。
而且,我两个都试过了xsl:value-of and xsl:copy-of to 输出内容。值输出纯文本并尊重我的格式(来自CSS),副本输出纯文本并破坏我的格式(返回到正文格式,忽略div和table)。
修改XSL以反映来自答案的建议。格式化是好的,但是嵌入的标记仍然以文本的形式出现,而不是被解释。