Re: [xsl] Unescaping < and >

Subject: Re: [xsl] Unescaping < and >
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 24 Jun 2003 18:33:12 -0400
Hi Arthur,

At 05:14 PM 6/24/2003, you wrote:
Is there any way of unescaping a "&lt;" and "&gt;" from a text() element.

No, although one occasionally hears rumors of extension elements to parse inline text-with-pseudo-markup into node structures. (Note you really need a node subtree, not a string of markup. The XSLT processor doesn't deal with markup and has no interest in it: all parsing has been done for it up front. Hence, you're not really asking for anything to be "unescaped" ... you're really asking for your text node to be parsed.)


I'd like to re-inject what is supposed to be xml, but is provided instead as escaped text within document elements.

This is an insidious and highly doubtful practice, both practically and in principle, but surprisingly common, leaving you with an ugly requirement. :-> (How do you know the stuff is well-formed? If the process guarantees it, then why not just fold it in as XML instead of disguising it as text-with-angle-brackets? If it doesn't, why are we pretending/hoping it does? I have yet to see a convincing use case for this.)


If you're using Saxon, I think later versions have an extension you can use, that returns a node set for a string. Otherwise, I couldn't say. You could use a pre-process to unescape the characters before parsing, and thereby run the risk of breaking your documents irremediably.

I've tried modifying the identity transform

It won't help. XSLT is designed to keep your mitts off the markup. On balance, this is a good thing. (Angle bracket mungling is really not so fun after a month or three.)


Note that what appears as "& g t ;" in a document *is* an angle bracket ">" -- but not a markup delimiter (that's the point).

This question comes up from time to time so someone else may have a more helpful answer.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread