xsl-list
[Top] [All Lists]

Re: De-escaping markup

2005-02-03 04:25:06
Hi Ben...

I have my head down on some things but I saw this message pop-up and
the subject line caught my attention as this is something I posted a
Javascript hack for yesterday.  In some cases you could just use
"disable-output-escaping" but that isn't true of all XSLT processors
as this is an optional part of the 1.0 spec.  MSXML supports "doe" but
Mozilla's TransforMiiX does not so when it comes to client-side
transformations you can't always expect "doe" to be available.

I've been coming across this issue a lot as of late as I am
transforming raw Atom feeds using client-side transformations.  In
looking around I couldn't find any solutions that made a whole lot of
sense so I wrote the following real quick.  You can find the posting
here >> 
http://www.xsltblog.com/codeoftheday/archives/2005/02/disable_output_1.html
<< Please excuse the state in which the posting is in as I am going
through a pretty major redesign and build for my blog.  None the less,
here's the code:

function doeHack(outputString, target){

// create reusable RegEx objects for "&lt;", "&gt;", and "&amp;"
var lt = new RegExp("&lt;", "g");
var gt = new RegExp("&gt;", "g");
var amp = new RegExp("&amp;", "g");

//create a reusable object represented by the target elements "id" value
var targetElement = document.getElementById(target);

//change the value of that objects "innerHTML" property using the
RegEx objects and the "replace" method of client-side Javascript
targetElement.innerHTML = outputString.replace(lt, "<").replace(gt,
">").replace(amp, "&");
}

I should note that I am using "Sarissa"'s serialize method to turn a
DOM object into an XML string but this obviously doesn't change any
escaped markup.  So I am calling this function like so:

doeHack(Sarissa.serialize(domobject), "id of HTML element to target output");

If you are unfamiliar with Sarissa I highly recommend it to help bring
sanity into the disparate world that is client-side XML processing. 
You can download the latest build for Sarissa on SF.net >>
http://sourceforge.net/projects/sarissa

A bit more explanation for this code is available on the above posting link.

Best of luck!

<M:D/>


On Thu, 3 Feb 2005 11:11:04 +0000, 
ben(_dot_)pickering(_at_)marketing(_dot_)net(_dot_)uk
<ben(_dot_)pickering(_at_)marketing(_dot_)net(_dot_)uk> wrote:
Hi

I have a bit of a problem in that a system out of my control is producing
"markup" looking like the following:

<CONTENT>
        This is &lt;b&gt;bold&lt;/b&gt;
</CONTENT>

i.e., with all the perfectly good markup escaped.

I was wondering if anyone knows of a stylesheet which will convert text
nodes like this into proper markup, for a whole document.  The above would
come out like:

<CONTENT>
        This is <b>bold</b>
</CONTENT>

Ideally it would operate on nested tags, as the system (which will remain
nameless) is also breaking my <table>s.

Thanks for any help.
Cheers,
Ben.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




-- 
<M:D/>

:: M. David Peterson ::
XML & XML Transformations, C#, .NET, and Functional Languages Specialist

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>