title: Manipulating character entities with XSL and string-to-codepoint
body: <p>I'm relatively new to XSL. I need to handle special characters (anything outside of the BasicLatin code block) in a particular manner. I understand that entity codes and literal characters are basically identical, but I have a need to work in a text editor that doesn't see it that way (and that is out of my control). So keeping the literal characters isn't an option. I'd like to handle this in my XSL rather than through Perl or some other mechanism, if that's possible. Here's what I have:</p>
  
  <pre><code>&lt;p&gt;This is a story&amp;#x2014;a long story.&lt;/p&gt;
  </code></pre>
  
  <p>This is my desired result:</p>
  
  <pre><code>&lt;p&gt;This is a story&lt;0x2014&gt;a long story.&lt;/p&gt;
  </code></pre>
  
  <p>I've been trying to do this via regular expression, something like:</p>
  
  <pre><code>&lt;xsl:value-of select="replace(., '(\P{IsBasicLatin})', 'concat('&amp;lt;0x', string-to-codepoints($1), '&amp;gt;'))"/&gt;
  </code></pre>
  
  <p>But I get an error that a separator is needed after a numeric literal. I haven't been able to find any documentation of that error that I understand. Is it related to my attempt to use functions as part of the replacement? Is such a thing allowed in XSL? If not, any suggestions would be welcome. I did review the answers provided here: <a href="https://stackoverflow.com/questions/10798974/convert-character-if-codepoint-within-given-range">convert character if codepoint within given range</a>, which seemed relevant but didn't work for me (the first wipes out my special characters, the second gives me very odd output.)</p>
  
  <p>Any help would be appreciated. I assume I'm missing something about either functions or codepoints, but I've hit a bit of a wall on my own. Thanks!</p>