[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Convert mutiple escaped items from xml to HTML

Subject: Re: Convert mutiple escaped items from xml to HTML
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 22 Aug 2001 10:38:16 +0100
lt xml convert
Hi Sun-fu,

> I have a xml with a series of escaped items shown in a text node and
> want to convert them into the html tag.

In effect, you are asking how to write an HTML parser in XSLT. As you
might expect, in a language that isn't particularly good at string
manipulation, it's not going to be easy. Someone with a computer
science background might be able to help with approaches to doing it.

In your situation, I would use disable-output-escaping - you would
save yourself a lot of work if you just did:

  <xsl:value-of select="Comment" disable-output-escaping="yes" />

In the example that you gave:

> <Comment>This is an example.&lt;br /&gt; &amp; you can find more
> information in &lt;a href="http://www.dot.com"&gt; dot.com
> &lt;/a&gt; &lt;br /&gt;</Comment>

the unescaped version of the content of Comment is unfortunately not
well-formed XHTML, nor even well-formed HTML. Unescaped, it is:

  This is an example.<br /> & you can find more information in <a
  href="http://www.dot.com"> dot.com </a> <br />

As you know, & characters have to be escaped in (X)HTML. So if they're
not double-escaped in your source XML, i.e. like:

  <Comment>This is an example.&lt;br /&gt; &amp;amp; you can find more
  information in &lt;a href="http://www.dot.com"&gt; dot.com
  &lt;/a&gt; &lt;br /&gt;</Comment>

then you should first run the value of Comment through a replacing
template to change all the '&' characters into the string '&amp;',
before giving its value with output escaping disabled.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.