I am trying to use XSLT to convert a simple XML schema to HTML and planned to use fn:replace to replace return ( \n ) with <p>; . However, I cannot figure out how to use this function correctly.
The simplified version of XSLT that I use reads:
<?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> <xsl:value-of select="fn:replace(value, '\n', '<p>')" /> </body> </html> </xsl:template> </xsl:stylesheet>
And the input to this XLST is, for example:
<?xml version="1.0"?> <root> <value><![CDATA[ Hello world! ]]></value> </root>
The conversion fails with an fn:replace error with a NoSuchMethodException. If I replaced the replace statement with
<xsl:value-of select="fn:replace('somestring', '\n', '<p>')" />
I get an IllegalArgumentException. How to use fn:replace to achieve what I want?
I am using Butterfly XML Editor to test XSLT.
xml xpath xslt
larsmoa
source share