I have an XML file that I need to transform. For one reason for another the XML contains escaped HTML data in its fields (the users are using an app I can't edit to generate the XML).


I know the best solution is to recreate the xml file with proper data, but as i stated that isn't an option currently. Is there a reasonably easy way to unescape this data for html output using an XSLT?

6 Years
Discussion Span
Last Post by iceandrews

The short answer is no, there is no way to unescape the data easily. The long is answer is a little bit more hopeful. There might be a way to do what you're asking but it requires a pretty complicated XSLT. Are you using XSLT 1.0 or 2.0 ? I assume since this is web oriented it'll be 1.0

If it is 1.0, this becomes a very difficult task. In 2.0 it becomes a little easier.


I am using 1.0 and this is my first time playing with xml its making my brain bleed a little bit. I've come across this function on another page:

function encodeDecodeResult(isChecked) {            
var html = jQuery("#result").html();            
if (isChecked) {                
html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,"<br/>").replace(/\r/g,""));            
} else {            
html.replace(/<BR>/g, "\n").replace(/&amp;/g, '&').replace(/&lt;/g, '<');

Which I think is doing what I want replacing the content of a div. I have have to figure out how to implement something like that. If I'm headed in the right (or wrong) direction please let me know.

Edited by fianna: n/a


Yes that's certainly the only direction you might be able to take. I tried to figure out an XSLT way to do this but it's much easier done in a script like that. Well done.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.