【发布时间】:2010-02-02 12:23:29
【问题描述】:
我正在尝试使用 XSLT 将简单的 XML 模式转换为 HTML,并计划使用 fn:replace 将返回 (\n) 替换为 <p>;。但是,我不知道如何正确使用此功能。
我正在使用的 XSLT 的简化版本如下:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:template match="/root">
<html>
<body>
<!-- Replace \n with <p> -->
<xsl:value-of select="fn:replace(value, '\n', '<p>')" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这个 XLST 的输入是例如:
<?xml version="1.0"?>
<root>
<value><![CDATA[
Hello
world!
]]></value>
</root>
fn:replace 上的转换失败并出现 NoSuchMethodException。如果我将替换语句更改为
<xsl:value-of select="fn:replace('somestring', '\n', '<p>')" />
我得到一个 IllegalArgumentException。如何使用fn:replace 来实现我想要的?
我正在使用Butterfly XML Editor 来测试 XSLT。
【问题讨论】: