title: Using XPath function fn:replace from XSLT
body: <p>I'm trying to use XSLT to convert a simple XML schema to HTML and planned to use <code>fn:replace</code> to replace returns (<code>\n</code>) with <code>&lt;p&gt;;</code>. However, I can't figure out how to use this function properly.</p>
  
  <p>A simplified version of the XSLT I'm using reads:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
  &lt;xsl:stylesheet version="1.0" 
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                  xmlns:fn="http://www.w3.org/2005/xpath-functions"&gt;
    &lt;xsl:template match="/root"&gt;
      &lt;html&gt;
        &lt;body&gt;
          &lt;!-- Replace \n with &lt;p&gt; --&gt;
          &lt;xsl:value-of select="fn:replace(value, '\n', '&lt;p&gt;')" /&gt;
        &lt;/body&gt;
      &lt;/html&gt;
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>And the input to this XLST is e.g.:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
  &lt;root&gt;
    &lt;value&gt;&lt;![CDATA[
      Hello
      world!
    ]]&gt;&lt;/value&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>The conversion fails on <code>fn:replace</code> with an NoSuchMethodException. If I change the replace statement to</p>
  
  <pre><code>&lt;xsl:value-of select="fn:replace('somestring', '\n', '&lt;p&gt;')" /&gt;
  </code></pre>
  
  <p>I get an IllegalArgumentException. How do I use <code>fn:replace</code> to achieve what I want?</p>
  
  <p>I'm using <a href="http://sourceforge.net/projects/butterflyxml/" rel="nofollow noreferrer">Butterfly XML Editor</a> to test the XSLT.</p>