这个简单的XSL转换有什么问题

时间:2011-01-24 06:26:46

标签: xml xslt

我正在学习XSLT并尝试一个非常简单的例子。这是我试过的 -

我要转换的源XML文件 -

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="reverse.xslt"?>
<Configuration>
  <MyConfiguration>
    <Value>
    </Value>
  </MyConfiguration>
</Configuration>

reverse.xslt文件中的转换 -

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <testNode>
       abc
    </testNode>
  </xsl:template>
</xsl:stylesheet>

当我在IE7中打开源文件时,我希望输出为 -

<testNode>
  abc
</testNode>

然而,我得到的是

abc

哪里出错?

编辑:源文件和转换文件都在同一个文件夹中。

1 个答案:

答案 0 :(得分:1)

你的xslt是绝对正确的,并且还产生你表达的输出。但HTML浏览器用于显示HTML代码。因此,您的预期输出<testNode> abc </testNode>也将被解释为HTML,因此只显示文本,因为testNode不是有效的HTML标记。

如果您使用Firefox打开文件并使用firebug进行检查,则会看到您的预期。

相关问题