我正在尝试使用XSLT将简单的XML模式转换为HTML并计划fn:replace用于替换returns(\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>
Run Code Online (Sandbox Code Playgroud)
此XLST的输入是例如:
<?xml version="1.0"?>
<root>
<value><![CDATA[
Hello
world!
]]></value>
</root>
Run Code Online (Sandbox Code Playgroud)
fn:replace使用NoSuchMethodException 转换失败.如果我将replace语句更改为
<xsl:value-of select="fn:replace('somestring', '\n', '<p>')" />
Run Code Online (Sandbox Code Playgroud)
我收到了IllegalArgumentException.我如何使用fn:replace来实现我想要的?
我正在使用Butterfly XML Editor来测试XSLT.