title: Encoding special chars in XSLT output
body: <p>I have built a set of scripts, part of which transform XML documents from one vocabulary to a subset of the document in another vocabulary.</p>
  
  <p>For reasons that are opaque to me, but apparently non-negotiable, the target platform (Java-based) requires the output document to have 'encoding="UTF-8"' in the XML declaration, but some special characters within text nodes must be encoded with their hex unicode value - e.g. '”' must be replaced with '<code>&amp;#x201D;</code>' and so forth. I have not been able to acquire a definitive list of which chars must be encoded, but it does not appear to be as simple as "all non-ASCII".</p>
  
  <p>Currently, I have a horrid mess of VBScript using ADODB to directly check each line of the output file after processing, and replace characters where necessary. This is painfully slow, and unsurprisingly some characters get missed (and are consequently nuked by the target platform).</p>
  
  <p>While I could waste time "refining" the VBScript, the long-term aim is to get rid of that entirely, and I'm sure there must be a faster and more accurate way of achieving this, ideally within the XSLT stage itself.</p>
  
  <p>Can anyone suggest any fruitful avenues of investigation?</p>
  
  <p>(edit: I'm not convinced that character maps are the answer - I've looked at them before, and unless I'm mistaken, since my input could conceivably contain <em>any</em> unicode character, I would need to have a map containing all of them <em>except</em> the ones I don't want encoded...)</p>