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).

<parent>
  <child>%3Cul%3E%3Cli%3EBoy+this+is+fun%21%3C%2Fli%3E%3C%2Ful%3E</child>
</parent>

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?

Recommended Answers

All 4 Replies

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) {                
jQuery("#result").html(                    
html.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g,"<br/>").replace(/\r/g,""));            
} else {            
jQuery("#result").html(                    
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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.